I have a string like
String str[]={"jan2011","feb2011","jan2010,"mar2012"};
How do I sort this by Date like: jan2010,jan2011,feb2011,mar2012
thanks for advance(not to use string functions more )
I have a string like
String str[]={"jan2011","feb2011","jan2010,"mar2012"};
How do I sort this by Date like: jan2010,jan2011,feb2011,mar2012
thanks for advance(not to use string functions more )
Hoi:
String[] unsorted={"jan2011","feb2011","jan2010","mar2012"};
List<String> unsortedList = Arrays.asList(unsorted);
Collections.sort(unsortedList);
String[] sorted = (String[])unsortedList.toArray();
This should do...
Assuming you have version 6 at your disposal, you can use the built-in
Collections.insertionSort(datavector, comparator);
However:
The Comparator class could be something along these lines:
public class DatestringComparator implements Comparator{
public int compare(String s1, String s2) {
// create Date instance based on the content of the input string
Date d1 = ....;
Date d2 = ....;
return d1.compareTo(d2);
}
}