Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, November 29, 2011

Split String on every UpperCase Letter, String Modify Array and String Join the array as a single word.


For example we have a string like “thisIsTheDay”

http://stackoverflow.com/questions/3752636/java-split-string-when-an-uppercase-letter-is-found

1.String sample = “thisIsTheDay”;
2.String[] sampleArray = sample.getChartType().split("(?=\\p{Lu})");
3.sampleArray = (String[])ArrayUtils.removeElement(sampleArray, "this");
4. String newStringName  = StringUtils.join(sampleArray," ");

Line 1: Declares a sample string.

Line 2: Splits the string for every unicode character that it encounters.

Line 3: Removes any unwanted words from the new array.

Line 4: Joins the elements of the array as a new word.