Quantcast
Channel: How can I sort an ArrayList? - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by dku.rajkumar for How can I sort an ArrayList?

ArrayList<A> list = new ArrayList<A>(); list.add(new A(5)); list.add(new A(3)); list.add(new A(1)); list.add(new A(8)); Comparator<A> comp = new Comparator<A>() { public int...

View Article



Answer by Guillaume for How can I sort an ArrayList?

Collections.sort(list, new Comparator<ElementClass> { @Override public int compare(ElementClass o1, ElementClass o2) { if (o1.getCounter() == o2.getCounter()) { return 0; } return o1.getCounter()...

View Article

Answer by Thilo for How can I sort an ArrayList?

Collections.sort(list, new Comparator<ElementClass>() { public int compare(ElementClass a, ElementClass b){ return a.getCounter()-b.getCounter(); }});

View Article

How can I sort an ArrayList?

I have an ArrayList of multiple instances of the class ElementClass. Inside the ElementClass is a method named getCounter() that returns the value of the variable counter inside that class. This...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images