Sorry if a beginner question, but im trying to read contents from a file in java, and separate 3 strings with a / between them, ex: john/casey/lambert, how would I go along separating these three strings so I can store them into a firstName middleName and lastName variable. Im not sure how to get my scanner or code to recognize the / as a stopping point.
Asked
Active
Viewed 31 times
0
-
[How to split a string in java](https://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – Amir Elsaeed Nov 16 '21 at 15:43
2 Answers
0
You can take the input in as string s = “John/Casey/lambert” and then you could split it into an array and take the values from there using s.split(“/“, -1)

Cade Weiskopf
- 81
- 10
0
String contents = "john/casey/lambert";
String contentsSplit[] = contents.split("/");
String firstName = contentsSplit[0]; //john
String lastName = contentsSplit[1]; //casey

JonR85
- 700
- 4
- 12