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
 */

fixed how to remove space in string in java

fixed how to remove space in string in java.
resently i have to remve from string here is exmape how to remove Whitespace from given string

/*******************************************************************************/
public class RemovingWhitespace {

    /**
     * @param args
     */
    public static void main(String[] args) {
       
        String st="2013 2014 2015 2016 3017 2018 2019 2120";
       
        String newString =st.replaceAll("\\s+","");
       
        System.out.println(newString);
    }

}

/*******************************************************************************/
/* Result is
 * 20132014201520163017201820192120
 */