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.
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]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With