Sorting parallel ArrayList I have a model class that contains 3 ArrayList which are in order by parallel of the same size. &lt;Object&gt;&lt;Calendar&gt;&lt;Long&gt; I want to sort it by the &lt;Long&gt; Is this the most clean? is there a better way? This doesn't seem memory efficient.

    public class ResultModel{
        private ArrayList&lt;Object&gt; sets = new ArrayList&lt;Object&gt;();
        private ArrayList&lt;Calendar&gt; dates=new ArrayList&lt;Calendar&gt;();
        private ArrayList&lt;Long&gt; unixtimes=new ArrayList&lt;Long&gt;();
    private class WinningSet implements Comparable&lt;WinningSet&gt;{
            private long unixtime;
            private Object set;
            private Calendar date;
            WinningSet(Object set,Calendar date,long unixtime){
                this.unixtime=unixtime;
                this.set=set;
                this.date=date;
            }
            @Override
            public int compareTo(WinningSet another) {
                return (int) (this.unixtime-another.getUnixtime());
            }
            public long getUnixtime() {
                return unixtime;
            }
            public Object getSet() {
                return set;
            }
            public Calendar getDate() {
                return date;
            }
        }
        public void sortSelf(){
            ArrayList&lt;WinningSet&gt; list=new ArrayList&lt;WinningSet&gt;();
            for(int i=0;i&lt;this.unixtimes.size();i++){
                list.add(new WinningSet(this.sets.get(i),dates.get(i),unixtimes.get(i)));
            }
            Collections.sort(list,Collections.reverseOrder());
            demap(list);
        }
        private void demap(ArrayList&lt;WinningSet&gt; list) {
             ArrayList&lt;Object&gt; tSets = new ArrayList&lt;Object&gt;();
             ArrayList&lt;Calendar&gt; tDates=new ArrayList&lt;Calendar&gt;();
             ArrayList&lt;Long&gt; tUnixtimes=new ArrayList&lt;Long&gt;();
            for(WinningSet temp:list){
                tDates.add(temp.getDate());
                tSets.add(temp.getSet());
                tUnixtimes.add(temp.getUnixtime());
            }
            this.sets=tSets;
            this.dates=tDates;
            this.unixtimes=tUnixtimes;
        }
}
1. Correctnes.

compareTo() method of the WinningSet class is not correct. As of now Integer.MAX_VALUE &lt; System.currentTimeMillis(). Consider the following example:

    long time1 = System.currentTimeMillis();
    System.out.println(time1 &gt; 3*Integer.MAX_VALUE);
    System.out.println(time1 - 3*Integer.MAX_VALUE);
    System.out.println((int)(time1 - 3*Integer.MAX_VALUE));


It could be the case that your events are generated around the same time and it will not result in any error but in general - e.g. in future, if you restore some serialized objects, it could lead to a possible problem. You can rewrite it int the following way:

        @Override
        public int compareTo(WinningSet another) {
            if (this.unixtime &gt; another.getUnixtime()) return 1;
            if (this.unixtime &lt; another.getUnixTime()) return -1;
            return 0;
        }


2. Performance

Copy of the 3 lists is indeed a bad thing. You can use set() method from ListIterator to traverse through the lists and replace values in place.

private void demap(ArrayList&lt;WinningSet&gt; list) {         
            Iterator li = list.iterator();
            Iterator si = sets.iterator();
            Iterator di = dates.iterator();
            Iterator ui = unixtimes.iterator();
            //you can add iterators for other lists here. 
            while (li.hasNext()) {// we assume number is the same
              WinningSet temp = li.next();
              si.next(); //need to advance to the right element;  
              di.next(); //need to advance to the right element;  
              ci.next(); //need to advance to the right element;  
              si.set(temp.getSet());
              di.set(temp.getDate());
              ui.set(temp.getUnixTime());
            }
        }


3. Design

Are you sure that instead of a 3 lists you can't consider TreeMap&lt;Long, SomeClass> where SomeClass is pair or Calendar and Object ? In this case you will always have the right order of items to work with - there is no need to sort lists on demand and do an extra work.