如何对以下数组进行排序String
?
String[] s = {"0.1", "0.3", "0.6", "0.4", "0.5", "0.2", "0.7", "0.8", "0.9", "0.10"};
通过排序,我并不是说将其转换为整数并将结果作为0.9
.
在这里,我想将值作为0.10
.
在这种情况下,如果字符串数组包含1.1
,则最大值将为1.1
。
如果数组是这样的,我可以得到最大值,即
String[] s = {"0.1", "0.4", "0.3", "0.4", "0.5", "0.2", "0.7", "1.8", "2.9", "3.1"};
我的代码将适用于这个字符串数组,但假设如果
String[] s = {"0.1", "1.4", "1.3", "0.4", "0.5", "0.2", "2.7", "1.8", "2.9", "0.1"};
我的代码。
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);
我怎样才能做到这一点?