split string only on first instance - java

前端 未结 6 637
情话喂你
情话喂你 2020-12-07 12:52

I want to split a string by \'=\' charecter. But I want it to split on first instance only. How can I do that ? Here is a JavaScript example for \'_\' char but it doesn\'t w

6条回答
  •  执念已碎
    2020-12-07 13:13

    As many other answers suggest the limit approach, This can be another way

    You can use the indexOf method on String which will returns the first Occurance of the given character, Using that index you can get the desired output

    String target = "apple=fruit table price=5" ;
    int x= target.indexOf("=");
    System.out.println(target.substring(x+1));
    

提交回复
热议问题