I am having trouble parsing a String into an object. I want to be able to take a String such as : "John Smith 1234" and parse it into a Person object (Person(String, String, int) )
To do this, I first tried turning the String into a String[] and splitting at the spaces. I can't figure out why this isn't working- I tried testing just this part of the method and I got this: [Ljava.lang.String;@1aa8c488
Here is my code:
public static Person parseToPerson(String s) {
String first = "";
String last = "";
String ID = "";
String[] splitArray = s.split("\\s+");
splitArray[0] = first;
splitArray[1] = last;
splitArray[2] = ID;
System.out.println(splitArray);
return new Person(first, last, Integer.parseInt(ID));
}
Thank you!