0 votes
in JAVA by
How to split a string in java?

2 Answers

0 votes
by
How to split a string in java?

public class JavaExample{

   public static void main(String args[]){

String s = "" ,ab;gh,bc;pq#kk$bb"";

String[] str = s.split(""[,;#$]"");

//Total how many substrings? The array length

System.out.println(""Number of substrings: ""+str.length);

for (int i=0; i < str.length; i++) {

System.out.println(""Str[""+i+""]:""+str[i]);

}

   }

}
0 votes
by

We can use split(String regex) to split the String into String array based on the provided regular expression.

Related questions

0 votes
asked Oct 20, 2020 in JAVA by sharadyadav1986
0 votes
asked Oct 21, 2020 in JAVA by rahuljain1
...