Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reference an Array element in a List of Arrays?

I have created a LinkedList of String arrays:

public static void main(String[] args){

    String[] one = new String[10];
    String[] two = new String[10];
    String[] three = new String[10];

    LinkedList<String[]> myList = new LinkedList<String[]>();

    myList.add(one);
    myList.add(two);
    myList.add(three);

}

My question is how do I now access an element of one of the arrays. For instance, I can access (or in the example print) the entire array element via:

System.out.println(myList.get(0));

But how do i access the first element in the String array that is owned by myList.get(0)? I tried everything like myList.get(0).[0], but I can't figure out how to access an element in an array, when the array is an element of a linked list.

like image 367
UFGator Avatar asked Mar 21 '23 10:03

UFGator


1 Answers

array.get(0)[index];

That should do the trick.

array.get(0) returns an array, all you have to do is add your index after it (no dot to separate).

Just the same way you would use one[index].

like image 62
Jeroen Vannevel Avatar answered Apr 02 '23 10:04

Jeroen Vannevel