How can I sort an array of String
String[] s = {"0.1","0.3","0.6","0.4","0.5","0.2","0.7","0.8","0.9","0.10"};
At my discretion, I do not mean here Converting it to Integer and getting 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 can get the maximum value if the array is like this.
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 array of strings, but suppose that
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 can i achieve this?