java - Sorting text with some rules -
i have arraylist follows
100 aaa 500-1 lorem ipsum 100 bbb 500-2 lorem ipsum 101 aaa 500-1 lorem ipsum 101 aaa 500-2 lorem ipsum 100 bbb 500-3 lorem ipsum i want sorted as
101 aaa 500-1 lorem ipsum 101 aaa 500-2 lorem ipsum 100 aaa 500-1 lorem ipsum 100 bbb 500-2 lorem ipsum 100 bbb 500-3 lorem ipsum first, descending number (101, 100).
second, ascending 3 letter word (aaa, bbb).
third, ascending third column (500-1, 500-2, 500-3)
i can split each element space , individual word , sort. can please me other way or known algorithm? please let me know if need more information.
thank in advance.
creation of comparator solve problem. should implement this:
public class mycomparator implements comparator<myobject> { public int compare(myobject o1, myobject o2) { if (o1 == null || o2 == null) { throw new nullpointerexception(); } if (o1.getvalue1() != o2.getvalue1()) { return integer.compare(o1.getvalue1(), o2.getvalue1()); } return integer.compare(o1.getvalue2(), o2.getvalue2()); } } of course there more ways solve problem, e.g., can implement own sorting algorithm. however, think use of comparator right "java-way" solve it.
Comments
Post a Comment