10:35 pm - Monday May 21, 2018

ArrayList Example Program for clone()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**
 @Author:candidjava.com
 @Description:cloning the arraylist
 */
import java.util.*;

public class DeeCloning {
	public static void main(String args[]) {
		ArrayList<String> al = new ArrayList<String>(); // creating the arraylist object

		al.add("sun"); // adding elements to the arraylist
		al.add("moon");
		al.add("star");
		System.out.println("actual arraylist:" + al); // display the arraylist
		ArrayList<String> copy = (ArrayList<String>) al.clone();// cloning the arraylist

		System.out.println("Cloned arraylist:" + copy); // display the cloned arraylist

	}
}

OUTPUT:
actual arraylist:[sun, moon, star]
Cloned arraylist:[sun, moon, star]

Filed in: Z-A All Java Codes

Comments are closed.