I am am trying to use the LinkedList class to load an array of anything. I was looking at the documentation of addAll method and it seem to me that I could load an array of stuff with very little effort.
addAll(int index, Collection<? extends E> c) Inserts all of the elements in the specified collection into this list, starting at the specified position.
But I am not so sure on how to structure it.
Let's just say I have an array of Objects and I am trying to load the objects into a link list.
How would I write this?
NOTE: I am trying to load it to a list because I will be deleting and adding at multiple times.
I used below code but I get an error:
int[] a = new int[5];
for(int index = 0; index<5; index++){
a[index] = index;
}
List<Integer> list = new LinkedList<Integer>();
list.addAll(Arrays.asList(a)); //error Here won't take a[]