java - How can I insert data between 2 nodes? -
don't know how it, need that, rest of code ok have insert number between numbers 8 , 10
class arra{ private arraylist<integer> lista; arra(){ lista = new arraylist<integer>(); } public void cargar(int i){ lista.add(i); } public arraylist <integer> traer(){ return lista; } public void insertarinicio(int i){ lista.add(0,i); } } public class trabclase { public static void main(string[] args) { // todo code application logic here arraylist<integer> li = new arraylist<integer>(); arra obj = new arra(); int i=0; for(i=2;i<=10;i=i+2){ obj.cargar(i); } li = obj.traer(); system.out.println("lista: "); system.out.println(li); obj.cargar(14); system.out.println("lista adicionando el 14 al final "); system.out.println(li); system.out.println("lista adicionando un valor al inicio"); obj.insertarinicio(0); system.out.println(li); } }
if can tell me how it, realy appreciate it, first of all, thanks
simply li.add(5, 9); 5 index number , 9 number want add.