ArrayList.clone(): This method is available in java.util.ArrayList class of Java.
Syntax:
Object java.util.ArrayList.clone()
This method returns a shallow copy of this ArrayList instance.
Parameter: NA
Returns: a clone of this ArrayList instance.
Exceptions: NA
Approach
Java
import java.util.ArrayList;public class ArrayListclone {public static void main(String[] args) {ArrayList<Integer> arr = new ArrayList<>();arr.add(1);arr.add(2);arr.add(3);System.out.println(arr.clone());}}
Output:
[1, 2, 3]
No comments:
Post a Comment