I want to create an empty LinkedList and using a ListIterator, add Integers to the List by always inserting them in the middle of the List. How to do that most efficiently.
Thank you
Inserting elements into a LinkedList at an index is inherently inefficient. Use an ArrayList or something else instead of LinkedList if you must insert at an index.
But if you need info on using ListIterators, look here:
http://www.java-examples.com/iterate-through-elements-java-linkedlist-using-listiterator-example
Or else you might just consider doing
myLL.add(i,val)
For more info see the Java API.
http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html
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