Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )

Have Programming Question? Ask it here!
 
 
 


ASHUTOSH PRADHAN
write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )
1 Answer(s)      3 years and 6 months ago
Posted in : Java Interview Questions


write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )


Advertisement
View Answers

February 4, 2011 at 5:37 PM


Use of HashSet and Iterator

The given code read the values using scanner class and stored into the HashSet. It does not allow duplicate values. Iterator class iterates the values and display it.

import java.util.*;

public class HashSetExample {
  public static void main(String [] args) {   
   Scanner input=new Scanner(System.in);
   System.out.println("Enter elements: ");
    int size;
    HashSet <String>set = new HashSet <String>();
    Iterator iterator;
    for(int i=1;i<=5;i++){
    String st=input.next();
    set.add(st);    
    }
    System.out.print("set data: ");  
    iterator = set.iterator();     
    while (iterator.hasNext()){
      System.out.print(iterator.next() + " ");  
    }
    System.out.println();

  }
}


Related Tutorials/Questions & Answers:
write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )
write aprogram which shows the use of hashset and iterator (through enter the value through keyboard )  write aprogram which shows the use of hashset and iterator (through enter the value through keyboard
write a program to create an vector and listeterator.and value should be enter through keyboard.
write a program to create an vector and listeterator.and value should be enter through keyboard.  write a program to create an vector and listeterator.and value should be enter through keyboard
Advertisements
write a program to create an vector and listeterator.and value should be enter through keyboard.
write a program to create an vector and listeterator.and value should be enter through keyboard.  write a program to create an vector and listeterator.and value should be enter through keyboard
write a program to create an arraylist and listeterator.and value should be enter through keyboard.
write a program to create an arraylist and listeterator.and value should be enter through keyboard.  write a program to create an arraylist and listeterator.and value should be enter through keyboard
write a program to create an vector and listeterator.and value should be enter through keyboard.
write a program to create an vector and listeterator.and value should be enter through keyboard.  write a program to create an vector and listeterator.and value should be enter through keyboard
write a program to create an arraylist and listeterator.and value should be enter through keyboard.
write a program to create an arraylist and listeterator.and value should be enter through keyboard.  write a program to create an arraylist and listeterator.and value should be enter through keyboard
write a program to create an vector with string(add,remove) operation.and value should be enter through keyboard.
write a program to create an vector with string(add,remove) operation.and value should be enter through keyboard.  write a program to create an vector with string(add,remove) operation.and value should be enter through keyboard
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.  write a program to create an arraylist with string(add,remove) operation.and value should be enter through
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.  write a program to create an arraylist with string(add,remove) operation.and value should be enter through
write a program to remove the element from hashset using keyboard.
write a program to remove the element from hashset using keyboard.  write a program to remove the element from hashset using keyboard
Example of Hashset iterator method in java.
Example of Hashset iterator method in java. In this exmple of HashSet class,  you will see the use of iterator() method. It is used for traversing all element from HashSet. Code:  HashSetRemoveElement.java package
Velocity Iterator Tool Example
Velocity Iterator Tool Example       This Example shows you how to use Iterator in velocity ...:- Initialize velocity run time engine through method  init(). 2:- Create object
HashSet Example
; In this section we are discussing HashSet with example code that shows... any element, use the remove() method which takes index as parameter. In order to remove all data from the HashSet use clear() method. When the HashSet is empty
Example of HashSet class in java
unique. You can not store duplicate value. Java hashset example. How.... Example of Hashset iterator method in java. Example of Hashset size() method...Example of HashSet class in java. In this part of tutorial, we
Collection : HashSet Example
time. It does not allow duplicate value. HashSet does not provide any its own... type. It returns true if your HashSet is empty. iterator()- Iterator type. It returns an iterator over the elements in the HashSet. remove(Object o
Can not input value into text field which use sx:datetimepicker
Can not input value into text field which use sx:datetimepicker  I am... value from calendar, it runs normal. But i input value from keyboard by hands and then i move focus to other element, that value is lost. Thus, i can not input
Can not input value into text field which use sx:datetimepicker
Can not input value into text field which use sx:datetimepicker  I am..." cssStyle="font-size:13.5px" accesskey="true" />"); I input value from calendar, it runs normal. But i input value from keyboard by hands and then i move focus
Define and use Macro in Velocity
Define and use Macro in Velocity       This Example shows you how to define and use macro in velocity  template and also shows how to use Iterator in velocity  template
jQuery auto complete through database using JSP shows error
jQuery auto complete through database using JSP shows error  The tutorial on jQuery titled "jQuery auto complete through database using JSP" shows error on browser when I try to select the one in the dropdown. Please help
HashSet In Java
HashSet is required to be synchronized explicitly. You may use...HashSet In Java In this section we will read about HashSet in Java. HashSet is a class of java.util package which extends an AbstractSet and implements
Iterator in Java Example
Iterator in Java Example We are going to discuss about iterator in java. Iterator is an interface in the collection framework and it works similar to the Enumeration. The java iterator traverse through all the elements
writing aprogram - Java Beginners
writing aprogram  Write a program to reverse any string  Hi Friend, Try the following code: import java.util.*; class StringReverse...); System.out.println("Enter string:"); String st=input.nextLine(); StringBuffer
What is HashSet in java
. The HashSet does not accept duplicate value. HashSet has many available methods like..."); //TC is a duplicate value System.out.println("HashSet is " + hashSet...In following example we will discuss about HashSet in Java. The HashSet class
Java HashSet  - Java Tutorials
Java Collections Framework- HashSet Class A HashSet is a collection set... is used to determine a unique value, called its hash code. The hash code is then used as an index at which the data associated with the key is stored
Java Set Iterator
Set Interface keeps the data without duplicate value. Its one subtype Treeset always returns sorted data. But the subtype HashSet doesnot return sorted data. It uses iterator() method to traverse the data Java Set Iterator
Java hashset example.
Java hashset example.     HashSet is a collection. You can not store duplicate value in HashSet. In this java hashset exmple, you will see how to create HashSet in java application and how to store value in Hashset
Write a program that (algorithmically) shows a times table.(convert integers to strings, format text, nested loops)
Write a program that (algorithmically) shows a times table.(convert integers to strings, format text, nested loops)   Write a java program that (algorithmically) shows a times table.(convert integers to strings, format text
Java Set iterator with example
Java Set Interface keeps the data without duplicate value. Its one subtype Treeset always returns sorted data. But the subtype HashSet doesnot return sorted data. It uses iterator() method to traverse the data Example of Java
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... through the above file and save it in maps depending on if it is a concept
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... through the above file and save it in maps depending on if it is a concept
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... through the above file and save it in maps depending on if it is a concept
write a program to use for loop print **********========== in c language
write a program to use for loop print **********========== in c language  write a program to use for loop print **========== in c language
Iterator tag example of struts2.2.1
to about the iterator tag. Iterator tag is used to iterate over a value. An iterable value can be either of: java.util.Collection, java.util.Iterator. We use...; <title>Value of iterator </title>
Java Hashmap Iterator
Java HashMap Iterator is a collection class. It implements the Map interface. It keeps the data in the key and value form. Java HashMap has no iterator method. So use the entrySet() method.It returns the data in Set object form
How to remove all element from Hashset.
How to remove all element from Hashset. HashSet is set type Collection. It supports only unique value. We can not store duplicate value in  it .In this example, you will see the use of clear method of HashSet. It is used to remove
Java arraylist iterator
ArrayList has iterator() method.Using iterator() method  elements of the arraylist easily gets retrieved. iterator() can be used... Iterator import java.util.ArrayList; import java.util.Iterator; import
What is an Iterator?
is iterator? In this programming tutorial it explain how to use the iterator interface with examples. visit to http://www.roseindia.net/tutorial/java/iterator...What is an Iterator?  Hi, What is an Iterator? Please help me
write a java program for pagination which will be configured by end user
write a java program for pagination which will be configured by end user  write a java program for pagination which will be configured by end user
Which java collection to use in scenario below and Why?
Which java collection to use in scenario below and Why?  I want to store thousands of record in a collection and later I want to search. For best and optimized results, which collection will I prefer
Java Hashtable Iterator
in the key and value form. Like hasmap, it has no iterator() method. Use the entrySet... be traversed by the Iterator. Java Hashtable Iterator Example import..."); hastab.put("e", "era"); Set s = hastab.entrySet(); Iterator
write a java program for pagination which will be configured by end user
write a java program for pagination which will be configured by end user  write a java program for pagination which will be configured by end user  
Java collection HashSet
Java collection HashSet  How can we use HashSet in java program?   The hashSet class is used to create a collection and store it in a hash table. Each collection refer to a unique value. import java.util.Collections
Which extension i use for save hibernate file.
Which extension i use for save hibernate file.   Please give me answer that which extension i use for save the hibernate file and how i run that file... which can be named by following the naming convention i.e. hibernate.cfg.xml
write a program which asks the user for two int values and calculates their sum.
write a program which asks the user for two int values and calculates their sum.  The title says it all, an example is (1,2) > 3
Java collection HashSet and TreeSet
Java collection HashSet and TreeSet   How can we used HashSet...("A"); //A is a duplicate value System.out.println("Set is " + set1... implementation of the interface in order to use it. Here Set is implemented by its
Iterator Java Order
. The iterator() method of the List Interface gives elements in propersequence. The iterator() method of the Set Interface gives elements inimproper sequence. Java Order Iterator Example import java.util.ArrayList; import
Java HashMap iterator and example
Java HashMap Iterator is an interface. It keeps the data in the key and value form. It is implemented by HashMap. hashMap doesnot have iterator method. So use the entrySet() method to get the data in Set object form. Set's all
Java For loop Iterator
Iterator can be used with the for loop also. Initialization of the Iterator is done before the for loop. Iterator has boolean value with the hasNext method. So no increment/decrement is required. Java for Loop Iterator
Write an Applet which display current date and time on the web page??
Write an Applet which display current date and time on the web page??  Write an Applet which display current date and time on the web page?  Here is an applet code that display date and time. import java.applet.
Write an Applet which display current date and time on the web page??
Write an Applet which display current date and time on the web page??  Write an Applet which display current date and time on the web page??  Here is an applet code that display date and time. import java.applet.
Advertisements
 

 

 

DMCA.com