Adding Elements to a List
by, 02-19-2012 at 06:47 AM (420 Views)
Elements are added to list by using these 4 different methods given below:
An item is added by it to end of list.Java Code:MyList.add("1"); //or MyList.add(varName);
At a particular location, elements could be added as given below.
Zero tells the element location, as given in above code. This is basically added as 1st element.Java Code:MyList.add(0, "2"); //or MyList.add(0, varName);
Other two ways of adding are self documented. They are addLast() & addFirst() functions. Just like add() methods, they are used.
Java Code:MyList.addFirst("3"); MyList.addLast("4");