String segmentation returns String array

Today, when I saw this piece of code, I didn't feel very understanding at first, so I will record it here:

String str = "adsa-sada_xa_xad_ada";
String aim = str.split("_")[1];

From the api explanation, it can be seen that after splitting is used, the returned string is an array of strings, so [1] means to take the string with index 1 in the array, which is the xa in [adsa-sada,xa,xad,ada]
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42258975/article/details/108642984