2:07 am - Saturday January 21, 2017

This Collections Program is used to set the elements using newSetFromMap() 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 Collections Program is used to set the elements using newSetFromMap() Method

Example Program


import java.util.*;

public class CollectionsDemo {
	public static void main(String[] args) {
		// create a list with n copies
		List list = Collections.nCopies(3, "java");

		// create an iterator
		Iterator itr = list.iterator();

		System.out.println("Values are :");
		while (itr.hasNext()) {
			System.out.println(itr.next());
		}
	}
}


 

Output:

Set is: [Java, C++, C]
Map is: {Java=true, C++=true, C=true}

Declaration:

  • public static <E> Set<E> newSetFromMap(Map<E, Boolean> map)

 

Parameters:

    map–The backing map

Return Value:

  •          The method call returns the set backed by the map.

 

Exception:

  • IllegalArgumentException –This is thrown if map is not empty.

 

 

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.