I have this txt file containing names and scores. "ex. Player1 35".
My program able to read it and store it to an Array of String.
Here's my question.
Is possible to separate the name and the score and store them in different Arrays?

ex. myArray = {"Player1 35","Player2 30"};

i want to save "Player1 -" in a String Array.
and "35" to an Int Array. If it is, then kindly give me some ideas on how to do it.
Ideas or sample code is much appreciated thank you.

6 Years
Discussion Span
Last Post by DoEds

It's easy to split up a string into an array of strings, using (eg) a blank as a delimiter

String s = "abc 123";
String[] parts = s.split(" ");
// now   parts[0] = "abc", parts[1] = "123"

To convert the score from String to int you can use the Integer.parseInt method.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.