How to split a string from the first space occurrence only Java

Dimitrios Sria :

I tried to split a string using string.Index and string.length but I get an error that string is out of range. How can I fix that?

while (in.hasNextLine())  {

    String temp = in.nextLine().replaceAll("[<>]", "");
    temp.trim();

    String nickname = temp.substring(temp.indexOf(' '));
    String content = temp.substring(' ' + temp.length()-1);

    System.out.println(content);
Alex Chermenin :

Must be some around this:

String nickname = temp.substring(0, temp.indexOf(' '));
String content = temp.substring(temp.indexOf(' ') + 1);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=448986&siteId=1