Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List objectCounter(List o, int number) {
- List<Brand> l = new ArrayList();
- HashMap<Integer,Object> objectlist = new HashMap<Integer, Object>();
- for (int i = 0; i < o.size(); i++) {
- Brand object = (Brand) o.get(i);
- if(objectlist.get(object.hashCode())==null){
- objectlist.put(object.hashCode(), object);
- object.setCounter(0);
- l.add(object);
- }else{
- object.setCounter(object.getCounter()+1);
- }
- }
- Collections.sort(l,new Comparator() {
- @Override
- public int compare(Object o1, Object o2) {
- Brand b1 = (Brand) o1;
- Brand b2 = (Brand) o2;
- int one = b1.getCounter();
- int two = b1.getCounter();
- if(one==two){
- return 0;
- }else if (one<two){
- return -1;
- }else{
- return 1;
- }
- }
- });
- return l;
- }
Add Comment
Please, Sign In to add comment