5:17 pm - Monday April 24, 2017

HashSet to use copy of another object Clone() method

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

BACK

This Program used to copy of another object using clone() method.

Example Program


package com.example;

import java.util.HashSet;

public class Retreive {
	public static void main(String a[]) {
		HashSet set = new HashSet();
		HashSet cc = new HashSet();
		set.add("Java");
		set.add(".Net");
		set.add("C,C++");
		cc = (HashSet) set.clone();
		System.out.println("Hash set values: " + set);
		System.out.println("Copy Hash set values: " + cc);
	}
}

Output:

 

Hash set values:[Java,.Net,C,C++]

Copy Hash set values:[Java,.Net,C,C++]

 

Description

The clone() method is used to return a shallow copy of this HashSet instance.

Declaration

Following is the declaration for java.util.HashSet.clone() method.

public Object clone()

Parameters

  • NA

Return Value

The method call returns a shallow copy of this set.

Exception

  • NA

BACK

Filed in: Z-A All Java Codes

Comments are closed.