I am having some difficulty with taking a String input from a user as shown in the code below, separating the tokens and shoving them into a string array. The input is recorded correctly however after I try to run the positions.split(" "); the dataString array does not take in the separated strings. What I am trying to do is take a set of numbers, ex: 1 3 4 then separate them into individual tokens and then instantiate a dataString string array that will have a length of 3 and the numbers 1, 3 and 4 inserted in each respective position.
Scanner input = new Scanner(System.in);
String[] dataString;
String positions;
...
System.out.print("Hand:" + currentHand);
input.nextLine();
System.out.print("\nEnter positions of cards to keep (e.g. 1 4 5 ):");
positions=input.nextLine();
dataString = positions.split(" ");
if (dataString.length > 5) {
System.out.print("You can hold a maximum of 5 cards");
positions = input.nextLine();
dataString = positions.split(" ");
}
input.close();