谁能向我解释一下这段代码,我没有太多的编码经验,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));
}
为什么这个循环只运行 3 次,而uniquelist
拥有stringList
. 循环不应该运行 10 次(长度uniqueList
)吗?