I was trying to test my skills and I try to do a test.
I receive the following input:
[7,11,10,6,9]
[21,24,25,23,26]
[116,115,117,120,121,119]
I need to sort all these values.
I try to do the following:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] parts = null;
List<String> linhas = new ArrayList<>();
for (int i = 0; i < 3; i++) {
String line = br.readLine();
line = line.replace("[","");
line = line.replace("]","");
line = line.replace(" ","");
System.out.println(line);
parts = line.split(",");
}
This way I got to show the output
7,11,10,6,9
21,24,25,23,26
116,115,117,120,121,119
The "String[parts]" got all values, but I don't know how to sort it, because the "parts" parameter is inside a "for loop".
How can I convert it to int/Integer and sort each line?
Integer.parseInt("string")...Also you can look atArrays.sort()...line = line.substring(1, line.length() - 1);to remove the brackets instead of replacing them one at a time.