Get your CodeRanch badge!*
The moose likes Performance and the fly likes JAVA stack implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "JAVA stack implementation" Watch "JAVA stack implementation" New topic
Author

JAVA stack implementation

Balaji Ambresh
Greenhorn

Joined: Nov 08, 2006
Posts: 7
Hi,
The Stack under java.util extends Vector instead of a LinkedList.
Vector is a resizable array. So, from what I know, it should make it heavy on memory management.
Also, we’re interested only on the top element of the stack. By using an linked list, we can get away with just one pointer.

So, why does Stack extend Vector?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Because Stack and Vector were part of Java 1.0; LinkedList came along many years later. The "List" interface was added to Vector at that time.


[Jess in Action][AskingGoodQuestions]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
Vector is a resizable array. So, from what I know, it should make it heavy on memory management.


Where did you get that idea? If you get the initial size guess right, the underlying Vector will never be resized.

LinkedList will always involve extra object (Entry) creation - see the source code.

Bill


Java Resources at www.wbrogden.com
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

Where did you get that idea? If you get the initial size guess right, the underlying Vector will never be resized.


He means that the Vector implementation uses an array.

Yes it is considered a design flaw since Vector's methods are exposed for an underlying Stack implementation.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA stack implementation
 
Similar Threads
Stack class
Type of null
Stack
Problem with stack class
Urgent: "coLLection timeout"