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

 
 


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

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

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 Pages:
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
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 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
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 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
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
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
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 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
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
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
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
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
Custom Iterator Tag in JSP
a Custom Iterator Tag here which will iterate for the number of times, in its attribute... JSP version shortname or prefix which we will use to call this tag. Tag... it has value "JSP" not "empty". attribute:  Iterator tag
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 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
This JDK Tutorial shows you how to wrap text inside cells of a JTable
JDK Tutorial - Multi-line cells in JTable in JDK 1.4+ This JDK Tutorial shows... focusing on Java in Europe, so please write to me if you would benefit... a TextAreaEditor. Something else which bothered me
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 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
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
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
A program which converts feet and inches to centimeters.
Java: Exercise - InchesToCm Write a program which converts feet and inches to centimeters. In this application we will write code for converting feet... and the "=" button Text field to display the converted value in centimeters
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
Write Keys and Values to the Properties file in Java
how to write keys and values in the properties files through the Java program... of the properties file by showing the message "Enter file name which has...));         System.out.println("Enter file name which has properties extension:");         str
Iterator in java
Iterator in java In this section you will learn about Iterator in java.  In order to cycle through the element of collection, iterator is used... are traversed based on index but Iterator in java is to traverse through object as well
Keyboard
for many keys, so you can not use the KeyTyped() listener method. You must write... of java.awt.event.InputEvent, so either can use these methods for determining which modifier keys... is down. Examples Example - KeyDemo - Shows use of KeyListener
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 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
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
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
Overview of Networking through JAVA
HostLookup.java. In which we call a InetAddress and make a object and pass the input value... are going to define class named "LocalPortScanner" in which we use... Overview of Networking through JAVA
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 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
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
Java Map iterator with example
Java Map Iterator is an interface. It keeps the data in the key and value form. It is implemented by HashMap, Tree Map. Map has no iterator method. So use the entrySet() method to get the data in Set object form. Use the entrySet
Overview of Networking through JAVA
Overview of Networking through JAVA  ... to write an application program require to communicate with the resources... summary of networking in a very simple manner that how to use URLs, sockets
Java Hasnext Iterator
Java HasNext Iterator is the method of the Iterator Interface. It returns the boolean.So it is used in the loop to traverse the next value. In case of false vale loop terminates. Java HasNext Iterator Example import
Use of write method of CheckedOutputStream class in java.
Use of write method of CheckedOutputStream class in java. In this tutorial, we will discuss the use of write(int b) method of CheckedOutputStream class... and calculate checksum value. The write(int b) method is used to write a bytes
Java HashSet Collection problem
Java HashSet Collection problem  Here's how the HashSet works.... equals always returns false and hashcode always returns a single value say 5... the concept behind this??   In your code, HashSet stores the values
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
Overview of Networking through JAVA
in the java.net package. Here we explain some example that shows the proper use...Overview of Networking through JAVA The Java platform is extremely preferable to write an application program require to communicate with the resources
Overview of Networking through JAVA
in the java.net package. Here we explain some example that shows the proper use...Overview of Networking through JAVA The Java platform is extremely preferable to write an application program require to communicate with the resources
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I am developing an JSP Application which supports I18N(Internationalization). In my....), how to manipulate date validations through JavaScript or Ajax? Thanks
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
using list iterator create student details - JavaMail
using list iterator create student details  write a java program... in ascending order using iterator(list iterator)  Hi Friend, First... which will describe you how to create Student class and add its properties
Use of Text Field
button etc.) through which users can input their data. A form is created using... Use of Text Field, Text box, Text Area, Checkbox,Dropdownlist and Radio...; By using form in HTML, users are allowed to enter or select different