JavaRush /Java Blog /Random EN /Sorting a string array.
Artemka58_1
Level 21

Sorting a string array.

Published in the Random EN group
How to sort an array without case sensitivity? To be more precise, sorting works, but incorrectly. If the first letter of the first element is uppercase, even if it is at the end of the alphabet, then the element does not change its position. There are no problems with other array elements. Here's my code: import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class G5_4 { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); ArrayList list = new ArrayList (); System.out.println("Введите строку: "); String s = read.readLine(); StringTokenizer z = new StringTokenizer(s); while (z.hasMoreTokens()) { list.add(z.nextToken()); } System.out.println("\nOriginal array is: "); for (String a : list) { System.out.print(a + " "); } System.out.println("\n\nSorted array is: "); Collections.sort(list); for (String a : list) { System.out.print(a + " "); } } }
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION