How do I separate string using space and dot

0 votes
Using above code I could retrive the String. Now I need to split it using space and then dot.
related to an answer for: read text file using Java

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

2 Answers

by (171 points)
selected by
0 votes
Best answer
You can use below code to split your String.


String[] splittedString = myString.split(","); // if (,) comma is your delimiter
by (327 points)
reshown by
0 votes
Try below line of code.

str = "1.Apple 2.Orange 3.Grape";
String[] splited = str.split("\\s+"); //This will cause any number of consecutive spaces to split your string into tokens.
for(int i=0;i<str.length;i++){
String[] newSplitted = splited[i].split(".");
System.out.println("Splited values:"+newSplitted[0] + " && " + newSplitted[1]);

Hope it helps