Java - Best way(main criteria is perfomance) to get part of a string before a given substring? -


i have string:

this string-tro:jjj me

i want string

this string-

i know can use method string#split colleagues said not best way because harm performance.

is there way doing that?

yes, can use string#substring method that:

string s = "this string-tro:jjj me"; system.out.println(s.substring(0,s.indexof("-")+1)); 

output:

this string-


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -