The Artima Developer Community
Sponsored Link

Java Buzz Forum
Remove all elements LinkedHashSet example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Remove all elements LinkedHashSet example Posted: Mar 15, 2016 12:21 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Remove all elements LinkedHashSet example
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
1.Basic java example program to remove all elements in linkedhashset
  • clear()   This method used to remove all elements from Linkedhashset.

  1. package com.removeelementLinkedhashset;
  2.  
  3. import java.util.LinkedHashSet;
  4. import java.util.Iterator;
  5.  
  6. public class LinkedHashsetExample{
  7.  
  8. public static void main(String[] args) {
  9.   
  10. LinkedHashSet<String> linkedhashset = new LinkedHashSet<>();
  11.        
  12.         linkedhashset.add("Java Interview Questions");
  13.         linkedhashset.add("Java interview program");
  14.         linkedhashset.add("Concept and example program");
  15.         linkedhashset.add("Concept and interview questions");
  16.         linkedhashset.add("Java Quiz");
  17.     
  18.       
  19. System.out.println("LinkedHashSet before removal : " + linkedhashset);
  20.  
  21.   boolean blnRemoved = linkedhashset.remove("Java Quiz");
  22.   System.out.println("Was Java Quiz removed from LinkedHashSet ? " + blnRemoved);
  23.   

  24.  
  25. System.out.println("LinkedHashSet after removal : ");
  26.  
  27. Iterator it=linkedhashset.iterator();
  28.              
  29. while(it.hasNext()){
  30. System.out.println(it.next());
  31.                      
  32. }   
  33.  linkedhashset.clear();
  34.  System.out.println("LinkedHashSet after removal  all elements"); 
  35.  
  36. }
  37.  
  38. }
     



Output:

  1. LinkedHashSet before removal : [Java Interview Questions, Java interview program, Concept
  2. and example program, Concept and interview questions, Java Quiz]
  3. Was Java Quiz removed from LinkedHashSet ? true
  4. LinkedHashSet after removal :
  5. Java Interview Questions
  6. Java interview program
  7. Concept and example program
  8. Concept and interview questions
  9. LinkedHashSet after removal all elements  :[]

Read: Remove all elements LinkedHashSet example

Topic: Java Annotated Monthly – March 2016 Previous Topic   Next Topic Topic: Check if a particular element exists in Java HashSet Example

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use