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
Post a Comment