top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Split String in java?

0 votes
584 views
How to Split String in java?
posted Jan 19, 2018 by Jon Deck

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The java string split() method splits this string against given regular expression and returns a char array.

public String split(String regex)   and,  
public String split(String regex, int limit)

Paramater

regex : regular expression to be applied on string.

limit : limit for the number of strings in array. If it is zero, it will returns all the strings matching regex.

Example

String string = "Query-Home";
String[] parts = string.split("-");
String part1 = parts[0]; // Query
String part2 = parts[1]; // Home
answer Jan 23, 2018 by Chahat Sharma
...