12:08 pm - Sunday June 25, 2017

Remove all elements from a collection boolean removeAll(Collection c)

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

                     The method public boolean removeAll(Collection<?c)  removes all the elements from the given collection. After performing removeAll function the set remains 0 elements.

Example Program


import java.util.LinkedHashSet;

public class HasRe 

{

	public static void main(String[] args) 
	
	{

		LinkedHashSet<String> lh = new LinkedHashSet<String>();

		lh.add("Add");

		lh.add("Sub");

		lh.add("Mul");

		lh.add("Div");

		System.out.println("Added Elements are :- ");

		for (String val : lh) 
		{

			System.out.println("Value = " + val);

		}

		System.out.println("Size of the set: " + lh.size());

		System.out.println("Removing all the elements");

		lh.removeAll(lh);

		System.out.println("Size of the set: " + lh.size());

	}

}

Output

   Added Elements are :-

   Value = Add

   Value = Sub

   Value = Mul

   Value = Div

   Size of the set: 4

   Removing all the elements

   Size of the set: 0

BACK

Filed in: Java Examples

Comments are closed.