Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
マルチマップを使用して、単語を長さで並べ替えています。整数は単語の長さです。リストに単語を追加する方法を考えていました。
Map<Integer, List<String>> mmap = new HashMap<Integer, List<String>>();
"bob" と "can" という 2 つの単語があるとします。どちらも 3 文字です。誰かが私がこれを行う方法について少し教えてもらえますか?
セットのリストを使用します。
private final List<Set<String>> list = new ArrayList<>(); public void add(String word) { while(list.size() <= word.length()) list.add(new HashSet<>()); list.get(word.length()).add(word); }