String.substring vs String[].split

前端 未结 5 1905
醉梦人生
醉梦人生 2021-01-17 09:24

I have a comma delaminated string that when calling String.split(\",\") it returns an array size of about 60. In a specific use case I only need to get the valu

5条回答
  •  Happy的楠姐
    2021-01-17 10:03

    You are certainly better off doing it by hand for two reasons:

    • .split() takes a string as an argument, but this string is interpreted as a Pattern, and for your use case Pattern is costly;
    • as you say, you only need the second element: the algorithm to grab that second element is simple enough to do by hand.

提交回复
热议问题