Java advanced (24) Java List set add and set method principles
Principles of the add and set methods in the JavaList set
The add method is used to add objects to the set list.
Syntax 1
Inserts a specified element at the end of the list. If the List set object is changed because the add method is called, true is returned; otherwise, false is returned. Add (Ee) e: Elements to be added to the list.
Instance
Public static void main (String [] args) {List
List = new ArrayList
(); List. add ("Protect the Environment"); // add a data list to the list. add (""); // add a data list to the list. add ("start from me"); // add data to the list // output the content in the list through a loop (int I = 0; I
Syntax 2
Insert a specified element at a specified position in the list, and Add 1 to the index of the element currently in this position and its subsequent elements. Voidadd (intindex, Eelement)
Index: used to insert the index at the specified element.
Element: Specifies the element to be inserted.
The index value starts from 0.
Set Method
The Set method is used to replace the elements in the Set list.
Voidset (intindex, Eelement)
Replace the element at the index with the element Object and return the new element.
Meiwenmeitu