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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Manoj Hunasigi
collections
1 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


please explain me d flow of this prog in detail

import java.util.*;

public class HashTreeLinkedhashset {
public static void main(String args[])
{
    HashSet hs=new HashSet();
    hs.add(new Integer(99));
    System.out.println("sri");
    hs.add("sri@jlc");
    System.out.println("sri");
    System.out.println(hs);

    TreeSet ts= new TreeSet();
    System.out.println(ts.add("sri"));
    ts.add("sri@jlc");
    System.out.println(ts.add("sri"));
    ts.add("aaaa");
    ts.add("cccc");

    ts.add("bbbb");
    System.out.println(ts);

}
}

Thanks


Advertisement
View Answers

April 19, 2011 at 12:55 PM


In the give code, an object of HashSet class is created.The add() method of this class then add an integer and a string value to it. The System.out.println(hs) then prints the values of HashSet.As HashSet is not ordered so it will display the hashset values in random order.

Then an object of TreeSet class is created. As add() method of TreeSet class is of boolean type so using System.out.println(ts.add("sri")), the value "sri" will get added to the TreeSet and display the true value on the console. The Set does not allow duplicate values so the value "sri" will not be added to the treeset again and when you add sri@jlc, it will display false value. The values "aaaa","cccc" and "bbbb" will directly added to the TreeSet and System.out.println(ts) display the Treeset values in random order as they are not ordered.



Related Tutorials/Questions & Answers:
Collections
Collections  Hi, Please send a study material on collections.../java/jdk6/introduction-collections-api.shtml http://www.roseindia.net/javacodeexamples/index.shtml http://www.devmanuals.com/tutorials/java/collections/index.html
collections
collections  why we need collections.when we will use collections in our applications
Advertisements
collections
collections  in collections can we perform binarysearch on arraylist elements without sorting them
what is collections?
what is collections?  what is collections
Collections API
Collections API  hello, What is the Collections API?   hi The Collections API is a set of classes and interfaces that support operations on collections of objects
Collections in Java
Collections in Java  What is Concurrent Hash map
Collections in Java
Collections in Java  What is Concurrent Hash map
java collections
java collections  what are all the methods and things added for collections in java5 and java6 please kindly reply me as soon as possible
Collections Framework
Collections Framework  Sir, We know that both HashMap & Hashtable is using for same purposes i.e Used for storing keys-values pair. But there is some difference between this two class that are 1)Hashtable is synchronized
collections in java
collections in java  please explain me the flow of this program..i m getting o/p as 2 1 1..y not 2 1 0..is it that if we change the i2 value,it doesnt remove. import java.util.*; public class Mapit { public static void main
java collections
achieve this plz without using stringtokenizer with any collections!!!  
Hibernate Criteria With Collections Example
Hibernate Criteria With Collections Example  Good code of Hibernate Criteria With Collections Example. Thanks   Example program of using Hibernate Criteria With Collections in your Java project. Check the tutorial
collections - Java Interview Questions
collections   what is the way to insert map values into a set in collections
 

 

 

DMCA.com