What does line.split(",")[1] mean [Java]?

SmashCode picture SmashCode · Apr 4, 2016 · Viewed 21.4k times · Source

I came across code where i had encountered with Double.valueOf(line.split(",")[1]) I am familiar with Double.valueOf() and my problem is to understand what does [1] mean in the sentence. Searched docs didn't find anything.

while ((line = reader.readLine()) != null)
                double crtValue = Double.valueOf(line.split(",")[1]);

Answer

dryairship picture dryairship · Apr 4, 2016

It means that your line is a String of numbers separated by commas.
eg: "12.34,45.0,67.1"

The line.split(",") returns an array of Strings.
eg: {"12.34","45.0","67.1"}

line.split(",")[1] returns the 2nd(because indexes begin at 0) item of the array.
eg: 45.0