How can I sort JSON by ID?

Solved

(I sorted a more simple ArrayList toolTimers first instead of sorting the JSON. )


import java.util.Collections; 
import java.util.Comparator;  

...


// vars for measuring Time (Space Bar and e)
ArrayList<ToolTimer> toolTimers = new ArrayList<ToolTimer>(); 

.....
  // this sorts 
  Collections.sort(toolTimers, new TimerComparator());

....




class TimerComparator implements Comparator<ToolTimer> {
  @Override
    public int compare (ToolTimer a, ToolTimer b) {

    if (a.timeArticleIndex.equals("") )
      println("equals ++++++++++++++++++++++++");

    //if a<b return -1;
    //if a==b return 0;
    //else return 1; 
    //return a.timeArticleIndex < b.timeArticleIndex ? -1 : 
    //  a.timeArticleIndex == b.timeArticleIndex ? 0 :
    //  1;

    return a.timeArticleIndex.compareToIgnoreCase( b.timeArticleIndex);
  }
}//class
1 Like