Presents your JAVA E-NEWSLETTER for June 23, 2003 <-------------------------------------------> UTILIZE THE METHODS IN THE STRINGUTILS CLASS The standard Java API provides acceptable support for string manipulation--but sometimes, acceptable just isn't enough. The Commons Lang StringUtils class picks up where the core API leaves off. There are tons of useful methods in the StringUtils class. If you need to center a string (perhaps for output), then use the center method: log(StringUtils.center("to be centered", 50, "*")); // ******************to be centered****************** If you've written the same number padding routine more than once, go ahead and use the one in StringUtils: log(StringUtils.leftPad("34", 8, "0")); // 00000034 Or, you can join an element of arrays, like this: log(StringUtils.join(new String[]{"cat","dog","carrot","leaf","door"},":")); // cat:dog:carrot:leaf:door If you need to capitalize a word or maybe even every word in a String, try the capitalise methods: log(StringUtils.capitaliseAllWords("a sentenced to be capitalised")); // A Sentenced To Be Capitalised When you need to count the number of times one String occurs in another, there's the countMatches method: log(StringUtils.countMatches("Bethany plays with army men", "e")); // 2 There's even a method for calculating the Levenshtein Distance between two strings: log(StringUtils.getLevenshteinDistance("David", "Jakob")); // 4 Though some of these examples are a bit contrived, you get the point. In order to use StringUtils, you have to download the Commons Lang package. Since you have the whole package available, be sure to take a look at what the rest of the package offers. There are classes to help with characters, numbers, exceptions, and even an enumeration class. http://jakarta.apache.org/commons/lang.html David Petersheim is a Senior Java Developer with Genscape, Inc. He designs and develops server-side applications to acquire and process real-time energy data. ----------------------------------------