Priyanshu Priyanshu - 1 year ago 87
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;

Answer Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download