誰でもこのコードを説明してもらえますか?私はコーディングの経験があまりないCollections
ので、これらの LOC を理解するのに苦労しています。
String[] stringList ={"1","2","1","1","2","3","2","3","2","1"};
List<String> al =Arrays.asList(stringList);
Set<String> uniqueList = new HashSet<String>(al);
for (String strCount :uniqueList) {
System.out.println(strCount + ": " + Collections.frequency(al, strCount));
}
uniquelist
のすべてのメンバーがあるのに、このループが 3 回しか実行されないのはなぜですかstringList
。ループを 10 回 (の長さuniqueList
) 実行するべきではありませんか?