File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Collection Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collection Interface" Watch "Collection Interface" New topic
Author

Collection Interface

wrushasen dakhane
Ranch Hand

Joined: Sep 25, 2006
Posts: 47
Hi,

1. Why Map is not part of the Collection Interface?

2. What is THashMap? and how it is benificial compared to HashMap?
(What do you mean by weakHashMap)

Wrushasen D.


SCJP 1.4, SCWCD 1.4
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39552
    
  27
Why Map is not part of the Collection Interface?

Are you asking why Map doesn't extend Collection? A Map is a collection of bindings from key to value, so there are always two elements involved (key and value). You can get collections of the keys, the values, and the bindings from the Map, though, if you need to treat those as Collection.


What is THashMap? and how it is benificial compared to HashMap?

Do you mean TreeMap? Have you read its javadoc? It spells out how it differs from HashMap. The same goes for WeakHashMap.


Ping & DNS - updated with new look and Ping home screen widget
wrushasen dakhane
Ranch Hand

Joined: Sep 25, 2006
Posts: 47
Yes I have gone through the javadoc for the same but unable to understand the reason for the same.

Can you please explain me the THashMap --- it is not TreeMap

Explain me the concept of WEakHashMap.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13881
    
  10

Where did you get "THashMap" from? That is not a class or interface in the standard Java API.

With some Googling I found this: GNU Trove: High performance collections for Java. That's probably where you got this from. Read the documentation there.
[ April 05, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
wrushasen dakhane
Ranch Hand

Joined: Sep 25, 2006
Posts: 47
Hello ,

You will get the information using the below link.

http://trove4j.sourceforge.net/javadocs/gnu/trove/THashMap.html
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That appears to be part of trove, not the JDK. As Jesper suggests, the trove documentation should say.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
bala nannaka
Ranch Hand

Joined: Apr 02, 2007
Posts: 49
WeakHashMap which is subtype of HashMap contains a weak object references.
weak object reference means It will not wait till garbage collector come and cleans when there is a no reference present it will be deleted immediately.

this is used for security purpose
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
That's a bit confusing or maybe incorrect. Removal will always "wait for the garbage collector" because that's what removes objects from memory.

WeakHashMap says: An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use. And once the key is gone, it removes the whole MapEntry. So when you put something in a WeakHashMap it will stay there as long as there is a strong reference to the key somewhere.

The map itself makes only a WeakReference to the key. WeakReference says when the GC finds that all references to an object are weak, it will make the object eligible for collection by breaking all the references.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Collection Interface
 
Similar Threads
Collections
Collection Interfaces
Doubt in Maop
interface question
regarding util package