以下のコードを使用してTreeSetインスタンスを作成しようとしていました。JavaのSetインターフェイスにlast()メソッドとfirst()メソッドが存在しない理由
Set<Integer> treeSet = new TreeSet<>();
treeSet.last() //gives compilation error
//solution here is either to cast the treeSet instance
//Or create treeSet using TreeSet concrete class. Which is not a best practice.
ここに続く予定はありますか?前もって感謝します。
:あなたは確かにあなたの供給のコードを変更することができるように
TreeSet
は、SortedSet
を実装しますか? https://stackoverflow.com/questions/9322405/converting-a-treeset-to-arraylist –