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