2012-07-02 54 views

回答

1

Collection.frequency()是你需要什麼,

試着這麼做,

ArrayList<Integer> intList // your list 

Set<Integer> Values = new HashSet<Integer>; 
Values.addAll(intList); // all duplicates removed. 

for (Integer i : Values) { 

int occurrences = Collections.frequency(intList, i); 
Log.e(i ," occurs " + occurences + " times."); 
} 
1

使用Collections.frequency()方法...

如:

public class ArrFrq { 

    public static void main(String[] args){ 
    ArrayList<String> s = new ArrayList<String>(); 


    s.add("Vivek"); 
    s.add("Vicky"); 
    s.add("Vivek"); 


    System.out.println(Collections.frequency(s, "Vivek")); 

    } 

} 
+0

喜感謝you..this也能正常工作.. – user1448108

相關問題