If each input of the array is seperated by a space you can use the split() method and choose something like yourArray.split("\\s+") or if they have end line characters you could do yourArray.split("\\n") for the end of line character. This method returns your String split up based on what's in the split method and give you back an array of each piece that was split up.
For example "1.2 2.3 8.9.7 4.2".split("\\s+") gives an array that contains {"1.2", "2.3", "8.9.7", "4.2"} Once you have this array you can feed the array into the method I provided.
public static String[] sortString(String[] input)
{
HashMap<Integer, String> mappedInputs = new HashMap<>();
ArrayList<Integer> values = new ArrayList<>();
for(String value : input)
{
//check that the input is a valid number
if(value.replace(".", "").matches("\\d+"))
{
mappedInputs.put(Integer.parseInt(value.replace(".", "")), value);
values.add(Integer.parseInt(value.replace(".", "")));
}
}
//use the collections built in method to sort
Collections.sort(values);
String[] sortedStrings = new String[values.size()];
//now grab the sorted numbers and add their mapped string values to the String array
for(int i = 0; i < values.size(); i++)
{
sortedStrings[i] = mappedInputs.get(values.get(i));
//debug to make sure they are sorted
System.out.println(sortedStrings[i]);
}
return sortedStrings;
}
public static void main(String[] args) {
String[] yourArray = {"1.2", "3", "2.1", "7.4.5"};
sortString(yourArray);
}//main method
I didn't use a Comparator just to show how this could be done without one, in case you haven't learned Comparators yet, and only used basic data structures to do basically the same thing. However a Comparator is much more flexible and if you have learned how to create them, use them.