11:19 pm - Sunday February 19, 2017

HashSet example program for Object[] toArray()

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: HashSet example program for Object[] to Array()

 */
import java.util.HashSet;

public class HashSetObjectToArray {

	public static void main(String[] args) {

		HashSet hSet = new HashSet(); // create a HashSet

		hSet.add(new Integer("1")); // add elements to HashSet object
		hSet.add(new Integer("2"));
		hSet.add(new Integer("3"));

		Object[] objArray = hSet.toArray(); // Object[] toArray() method.

		System.out
				.println("HashSet elements are copied into an Array.Now Array Contains.."); // display
																							// contents
																							// of
																							// Object
																							// array
		for (int index = 0; index < objArray.length; index++)
			System.out.println(objArray[index]);
	}
}

Output

HashSet elements are copied into an Array.Now Array Contains..
1
2
3

BACK

Filed in: Z-A All Java Codes

Comments are closed.