The program starts by creating an ArrayList named list_col and adding some String elements to it using the add() method.
Next, the program uses the clone() method to create a new ArrayList named clone_new which is an exact copy of list_col.
Finally, the program prints out the original list_col ArrayList and the cloned clone_new ArrayList using the println() method.
import java.util.ArrayList; import java.util.Collections; public class Clone_ArrayList { public static void main(String[] args) { ArrayList<String> list_col = new ArrayList<String>(); list_col.add("Pink"); list_col.add("Yellow"); list_col.add("Black"); list_col.add("White"); list_col.add("Blue"); list_col.add("Orange"); System.out.println("Given Array List : " + list_col); ArrayList<String> clone_new = (ArrayList<String>)list_col.clone(); System.out.println("Cloned Array List : " + clone_new); } }
Given Array List : [Pink, Yellow, Black, White, Blue, Orange] Cloned Array List : [Pink, Yellow, Black, White, Blue, Orange]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions