Java split () method
split () method matches the given regular expression to split strings.
grammar
public String[] split(String regex, int limit)
parameter
regex - the regular expression delimiter.
limit - split shares.
return value
The success of the replacement string is returned, then failed to return the original string.
Examples
public class Test { public static void main(String args[]) { String Str = new String("Welcome-to-w3big.com"); System.out.println("返回值 :" ); for (String retval: Str.split("-", 2)){ System.out.println(retval); } System.out.println(""); System.out.println("返回值 :" ); for (String retval: Str.split("-", 3)){ System.out.println(retval); } System.out.println(""); System.out.println("返回值 :" ); for (String retval: Str.split("-", 0)){ System.out.println(retval); } System.out.println(""); System.out.println("返回值 :" ); for (String retval: Str.split("-")){ System.out.println(retval); } } }
The above program execution results:
返回值 : Welcome to-w3big.com 返回值 : Welcome to w3big.com 返回值 : Welcome to w3big.com 返回值 : Welcome to w3big.com