how to split a string
Community Q&A. Before Java 1.4, StringTokenizer was used to split String in Java. After JDK 1.4, the use of StringTokenizer is discouraged, and instead the String.split(...) method or use of java.util.regex package is encouraged. Steps. Using split method: Java String class defines two split methods to split Java String object. (1) String[] split( String regEx) which splits the string according to given regular expression. (2) String[] split( String regEx, int limit ), which splits the string according to given regular expression. The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. Code snippet for String[] split( String regEx)