次の配列を並べ替えるにはどうすればよい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);
どうすればこれを達成できますか?