Skip to content
Advertisement

How can i sort a string without using sort() method in java?

I want to sort a string “computer” -> “cemoprtu”, but without using Arrays.sort(string).

Advertisement

Answer

Looks like you need to sort the characters, so I’d start with

String input = "computer";
char[] characters = input.toCharArray();
//now sort characters using some algorithm
String output = new String(sorted_characters); //sorted_characters might be characters after sorting, if you sort in place
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement