How can I sort the following array, String
?
String[] s = {"0.1", "0.3", "0.6", "0.4", "0.5", "0.2", "0.7", "0.8", "0.9", "0.10"};
By sort I don't mean here converting it into in an integer and get the result as 0.9
.
Here I want to get the value as 0.10
.
Here in this case if the string array contains 1.1
then the maximum value will be 1.1
.
I am able to get the maximum value if the array is like this, i.e.,
String[] s = {"0.1", "0.4", "0.3", "0.4", "0.5", "0.2", "0.7", "1.8", "2.9", "3.1"};
My code will work for this string array, but suppose if the
String[] s = {"0.1", "1.4", "1.3", "0.4", "0.5", "0.2", "2.7", "1.8", "2.9", "0.1"};
My code.
public String createNewVersion(
String[] entityVersionHistory) {
Map<Integer, List<Integer>> m_Map1 = new HashMap<Integer, List<Integer>>();
String prevKey = "0";
String currentKey = null;
List<Integer> list = new ArrayList<Integer>();
for (String str: entityVersionHistory)
{
String[] splitVersion = str.split("\\.");
currentKey = splitVersion[0];
if(!prevKey.equals(currentKey))
{
Integer s = new Integer(splitVersion[1]);
m_Map1.put(Integer.valueOf(prevKey), list);
list = new ArrayList<Integer>();
list.add(s);
prevKey = currentKey;
}
else
{
Integer s = new Integer(splitVersion[1]);
list.add(s);
}
}
m_Map1.put(Integer.valueOf(prevKey), list);
How I can achieve this?