Hello, I have this little piece of code

System.out.println("Write a sentence: ");
    String sentence = tastatur.next();
    String[] temp;
    String divider = " ";
    temp = sentence.split(divider);

The problem is that when I enter a sentence only the first word gets stored in the string. For instance if I enter "dum di du", only "dum" will get stored. How can I solve this so the whole sentence gets stored in the string?

Nevermind, I figured it out. I needed to put tastatur.nextLine() in line 2.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.