Saturday, 12 April 2014

Fixed How to split a String by space or whitespace

Fixed How to split a String by space or white space

/*
 *
 */
public class SplitByWhitespace {

    /**
     * @param args
        public static void main(String[] args) {
       
        String  str = "How to split a String by space";
        String[] splited = str.split("\\s+");
        for(String splitedValue : splited){
        System.out.println("splitedValue :"+splitedValue);
        }
    }
}
/* Result
 *
 * splitedValue :How
splitedValue :to
splitedValue :split
splitedValue :a
splitedValue :String
splitedValue :by
splitedValue :space
 */

No comments:

Post a Comment