Remove first word from a string in Java

前端 未结 9 1979
天涯浪人
天涯浪人 2020-12-29 12:20

What\'s the best way to remove the first word from a string in Java?

If I have

String originalString = \"This is a string\";

I want to r

9条回答
  •  情话喂你
    2020-12-29 12:53

    Simple.

     String o = "This is a string";
     System.out.println(Arrays.toString(o.split(" ", 2)));
    

    Output :

    [This, is a string]
    

    EDIT:


    In line 2 below the values are stored in the arr array. Access them like normal arrays.

     String o = "This is a string";
     String [] arr = o.split(" ", 2);
    
     arr[0] // This
     arr[1] // is a string
    

提交回复
热议问题