I am having string list which consists of integer values. i just want to sort in ascending as well as in descending order.
ArrayList<String> a = new ArrayList<String>();
a.add("1435536000000");
a.add("1435622400000");
System.out.println("Before : " + a);
Collections.sort(a, new ComparatorOfNumericString());
System.out.println("After : " + a);
My ComparatorOfNumericString class is -
public class ComparatorOfNumericString implements Comparator<String> {
@SuppressLint("NewApi")
@Override
public int compare(String lhs, String rhs) {
int i1 = Integer.parseInt(lhs);
int i2 = Integer.parseInt(rhs);
return Integer.compare(i1, i2);
}
}
Any one having idea how to sort this strings having integer values in java?
Thanks a lot!! in Advance!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…