62,616
社区成员
发帖
与我相关
我的任务
分享
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.bag.TreeBag;
public class ApplicationRunner
{
public static void main( String[] args )
{
List < Integer > list = new ArrayList < Integer >();
Bag bag = new TreeBag( list );
Object[] values = bag.uniqueSet().toArray();
for( int i = 0 , count = values.length ; i < count ; i++ )
{
System.out.println( values[i] + "在List中存在" + bag.getCount( values[i] ) + "个" );
}
}
}
import java.util.*;
public class Test2{
public static void main(String [] args) {
Integer[] arr={1,1,2,2,3,3,3,4,4};
List<Integer> myList=Arrays.asList(arr);
HashSet<Integer> hs=new HashSet<Integer>(myList);
for(Integer i:hs){
System.out.println(i+" 在List中存在" + Collections.frequency(myList,i) + "个");
}
}
}