Priyanshu Priyanshu - 3 months ago 26
Java Question

Working with String in Java

Arrange string in alphabetical order. Can anybody please help me on this? Thanks in advance.

public class zI

public <T> String(T text)
char[] charArray = text.toCharArray();
String sortedString = new String(charArray);
return sortedString;


Replace the line

char[] charArray = text.toCharArray();


char[] charArray = text.replace( " ","" ).toLowerCase().toCharArray();

You could also use regex:

char[] charArray = text.toLowerCase().replaceAll( "[^\\p{Lower}]","" ).toCharArray();