What does [1] at the end of statement mean?
String magnitudeString = details.split(" ")[1];
Can’t it be written like this:
String [] magnitudeString = details.split(" ");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
[1]is indexing an array: the result ofString.split()is an array, and[1]is taking the second element from that result.This is equivalent to:
So it can’t be re-written quite like your suggestion.
Obviously either of these is a problem if the result of
splithas fewer than 2 elements, so alengthcheck before accessing array elements is prudent, and the immediate form won’t allow this.