ArrayList.add(E): This method is available in java.util.ArrayList class of Java.
Syntax:
boolean java.util.ArrayList.add(Ee)
This method takes one argument. This method appends the specified element to the end of this list.
Parameters: One parameter is required for this method.
e: the element to be appended to this list.
Returns: true
Exceptions: NA
Approach
Java
import java.util.ArrayList;public class ArrayListAdd {public static void main(String[] args) {ArrayList<Integer> arr = new ArrayList<>();arr.add(1);arr.add(5);arr.forEach((n -> System.out.print(n + " ")));}}
Output:
1 5
No comments:
Post a Comment