0

I have a LinkedList like this

 LinkedList l = new LinkedList();
    l.add("1");
    l.add("2");
    l.add("3");
    l.add("4");
    l.add("5");
    l.add("6");

i want move the value 6 to before 3 and also deleted in the old position.

I need a command like this l.move(5 to 3) or l.shift(5 to 3).

I can manually do like

String s = l.get(5);
l.add(2,s);
l.remove(6);

Thanks

user1023675
  • 289
  • 1
  • 4
  • 13
  • 1
    Be careful: with `get(5)`, you're getting the entry at index 5, not the entry that value is 5 (as I believe you were expecting). Same for the other methods of List you're using. – sp00m Mar 20 '14 at 11:10
  • Don't use [raw types](http://docs.oracle.com/javase/tutorial/java/generics/rawTypes.html). – Boris the Spider Mar 20 '14 at 11:10
  • 1
    http://stackoverflow.com/questions/450233/generic-list-moving-an-item-within-the-list ? – Marco Acierno Mar 20 '14 at 11:12

1 Answers1

0

There are no built-in java methods to do what you are asking for in the LinkedList class, so you will have to define your own method, or create a class that extends LinkedList and add this functionality to that class.

anirudh
  • 4,116
  • 2
  • 20
  • 35