java.util.ArrayList.set (int index, E Element) replaces the element with the specified element at the specified position in this list.
Statement
The following is a declaration of the Java.util.ArrayList.set () method
Public E Set (int index, e Element)
Parameters
return value
This method returns the element before the specified position.
Abnormal
Example
The following example shows the use of the Java.util.Arraylist.set () method.
Package Com.yiibai;import Java.util.arraylist;public class Arraylistdemo {public static void Main (string[] args) { c1/>//create an empty ArrayList with an initial capacity arraylist<integer> arrlist = new arraylist<integer& gt; (5); Use Add () method to add elements in the list arrlist.add (n); Arrlist.add (a); Arrlist.add (+); Arrlist.add (a); Let us print all the elements available in list for (Integer number:arrlist) { System.out.println ("number = "+ number); } Inserting elment at 3rd position Arrlist.set (2,55); Let us print all the elements available in list System.out.println ("Printing new list:"); for (Integer number:arrlist) { System.out.println ("number =" + number);}}}
Let's compile and run the above program, which will produce the following results:
Number = 15Number = 20Number = 25Number = 22Printing new List:number = 15Number = 20Number = 55Number = 22
Transferred from: http://www.yiibai.com/java/util/arraylist_set.html
"Go" Java.util.ArrayList.set () Method instance