8:05 am - Sunday August 20, 2017

Remove elements using boolean remove(Object o)

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 remove(Object o) removes the particular element from the linkedhashset,if the element is present.Also,returns true if the element is present,Otherwise returns false.

Example Program


import java.util.LinkedHashSet;

public class LinkedHashSetRemove 

{

	public static void main(String[] args) 
	
	{

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

		lh.add("Add");

		lh.add("Sub");

		lh.add("Mul");

		lh.add("Div");

		lh.add("Expo");

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

		for (String value : lh)

		{

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

		}

		lh.remove("Div");

		System.out.println("Now size of set is: " + lh.size());

		for (String value : lh)

		{

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

		}

	}

}

Output

      Size of set is: 5

      Value = Add

      Value = Sub

      Value = Mul

      Value = Div

      Value = Expo

      Now size of set is: 4

      Value = Add

      Value = Sub

      Value = Mul

      Value = Expo

BACK

Filed in: Java Examples

Comments are closed.