0
How can I insert?
ort java.util.LinkedList; public class MyClass { public static void main(String[ ] args) { LinkedList<String> c = new LinkedList<String>(); c.add("Red"); c.add("Blue"); c.add("Green"); c.add("Orange"); c.remove("Green"); // can I insert for example yellow after blue in that moment? } }
3 Respuestas
+ 5
LinkedList.add(int location,E element);
e.g.
c.add(2,"yellow");
+ 1
you can find the index of "blue" like this:
int getIndex(String element,List list){
for(int i=0;i<list.size();i++){
if(element.equals(list.get(i))return i;
}
}
or just :
list.indexOf("blue");
0
c.add(2,"ellow");