简体   繁体   中英

Java string.split() convention

I'm using the following line of code in my program to get the first part of a string.

struct.trailing.split(" ")[0]

For example, the string "Dogs and cats" would return "Dogs" with this line of code. Is what I wrote convention? I tried this at random and it worked, piquing my curiosity,

StringTokenizer also can be used
StringTokenizer st2 = new StringTokenizer(str, " ");
do the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM