My need is to sort the ArrayList of Strings, based on specific index range. For example I have following items in list: [\"abc\", \"xyz\", \"pqr\" , \"asd\"]
Now
You should do
Collections.sort(yourList.subList(1, yourList.size()));
Since the List.subList
method returns a view of the list, modifications done by Collections.sort
will affect the backing list as well.
DetailsVOTemp
Model have Time and Add set-get method
and I have already one list which is a list with the name of list
Get the time and lat long from the list and store in tow ArrayList
than finally sort it
List< DetailsVOTemp> firstlist = new ArrayList<>();
List<DetailsVOTemp> secondlisr = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
DetailsVOTemp mDetailsVOTemp = new DetailsVOTemp();
mDetailsVOTemp.setTime(list.get(i).getTime());
mDetailsVOTemp.setAdd(list.get(i).getLatLong());
mVoTemps.add(mDetailsVOTemp);
}
for (int i = 0; i < list.size(); i++) {
DetailsVOTemp mDetailsVOTemp = new DetailsVOTemp();
mDetailsVOTemp.setTime(list.get(i).getDropOffTime());
mDetailsVOTemp.setAdd(list.get(i).getDropLatLong());
mVoTemps1.add(mDetailsVOTemp);
}
mVoTemps.addAll(mVoTemps1);
Collections.sort(mVoTemps, new Comparator<DetailsVOTemp>() {
@Override
public int compare(DetailsVOTemp o1, DetailsVOTemp o2) {
return o1.getTime().compareTo(o2.getTime());
}
});
StringBuilder mBuilder = new StringBuilder();
StringBuilder mBuilder1 = new StringBuilder();
for (int i = 0; i < mVoTemps.size(); i++) {
mBuilder1.append(mVoTemps.get(i).getTime() +" :: ");
mBuilder.append(mVoTemps.get(i).getAdd() +" :: ");
}
Log.d("Time : ", mBuilder1.toString());
Log.d("Address : ", mBuilder.toString());