0

Is is possible to get out of an ArrayList the first number of the first index?

Here's an Example:

In there are 5 items:

path = {0.5,5.0},{0.6,6.0},{0.7,7.0},{0.8,8.0},{0.9,9.0}

And I want to get the number 5.0 out of {0.5,5.0}...

I tried it with path.get(0) But it only gives me {0.5,5.0} back.

Is it possible to get 5.0 out of it without getting all the other numbers?

Idos
  • 15,053
  • 14
  • 60
  • 75
genaray
  • 1,080
  • 1
  • 9
  • 30

2 Answers2

2

If your ArrayList contains arrays, this is the way to go

myList.get(0)[1] // You're getting the index 1 from the 1st array of your ArrayList

Otherwise, if it is containing other ArrayList's

myList.get(0).get(1) // Same logic as above applied to the Collection
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
1

If your curly braces in the ArrayList are actually brackets (they probably are), you can use:

myArray.get(0)[index] to get the index you want. In your example it is:

myArray.get(0)[1];

Note: if your ArrayList elements are also ArrayList then you need to use get(0).get(1) instead of get(0)[1].

Idos
  • 15,053
  • 14
  • 60
  • 75