Copilot
Your everyday AI companion
About 16,500,000 results
  1. The string split() method breaks a given string around matches of the given regular expression. After splitting against the given regular expression, this method returns a string array.

    Input String: 016-78967
    Regular Expression: -
    Output : {"016", "78967"}
    // Java program to demonstrate working of split(regex,
    // limit) with small limit
    public class GFG {
    // Main driver method
    public static void main(String args[])
    {
    // Custom input string
    String str = "geekss@for@geekss";
    String[] arrOfStr = str.split("@", 2);
    Content Under CC-BY-SA license
    Was this helpful?

    See results from:

  2. People also ask
    There are three ways you can split a string in java, first and preferred way of splitting a string is using the split () method of string class. The second way is to use the Scanner class. Other way is using the StringTokenizer class, which is a legacy class and not recommended anymore.
    Java split () function is used to splitting the string into the string array based on the regular expression or the given delimiter. The resultant object is an array contains the split strings. In the resultant returned array, we can pass the limit to the number of elements.
    Use the appropriately named method String#split (). String string = "004-034556"; String [] parts = string.split ("-"); String part1 = parts ; // 004 String part2 = parts ; // 034556 Note that split 's argument is assumed to be a regular expression, so remember to escape special characters if necessary.
    It simply splits the given String based on the delimiter, returning an array of Strings. Let us look at some examples. We'll start with splitting by a comma: String [] splitted = "192.168.1.178" .split ( "\\.") Let's now split by multiple characters – a comma, space, and hyphen through regex: