-1

Hi I'm trying to read an input from the user like "Bananas apples oranges" but I want to store each fruit in a different String variable. Is there a way to do this?

Thank you in advance.

1 Answers1

0

I guess you should split the text.

Well, I think this may be a intuitive example that I found:

    String str = "Bananas apples oranges"; 
    String[] arrOfStr = str.split(" ", 2); 

    for (String a : arrOfStr) 
        System.out.println(a);

The second argument in Split method is the limit which is used for the result being produced and it can be either positive, negative or zero.

Ethan
  • 301
  • 1
  • 5
  • 19