permaculture playing cards*
The moose likes Java in General and the fly likes Need help creating arraylist of stacks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help creating arraylist of stacks" Watch "Need help creating arraylist of stacks" New topic
Author

Need help creating arraylist of stacks

John Laker
Greenhorn

Joined: Oct 01, 2010
Posts: 22
I'm implementing Dijkstra's algorithm in Java. I need help in creating an arraylist of stacks that will be used to store the predecessors table, which means that for every element's shortest path, the predecessors taken to get there would be in the stack.

Here's the code I have


I'm unable to add the the stack to prev arraylist. The error is

The method add(E) in the type ArrayList<E> is not applicable for the arguments (predec<E>)
.

I have implemented a TreeMap, with the mainNodes arraylist storing all the elements in the map.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

http://download.oracle.com/javase/tutorial/java/generics/index.html
http://download.oracle.com/javase/tutorial/extra/generics/index.html


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19682
    
  20

You probably meant ArrayList<Stack<WhateverClassTheStackHolds>>.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John Laker
Greenhorn

Joined: Oct 01, 2010
Posts: 22
Rob Prime wrote:You probably meant ArrayList<Stack<WhateverClassTheStackHolds>>.


oh, so you mean define arraylist like

ArrayList <Stack <E>> since stack needs to hold generic type objects of type E ?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

Rob Prime wrote:You probably meant ArrayList<Stack<WhateverClassTheStackHolds>>.

Thanks Rob, that's right. I was careless.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

John Laker wrote:
Rob Prime wrote:You probably meant ArrayList<Stack<WhateverClassTheStackHolds>>.


oh, so you mean define arraylist like

ArrayList <Stack <E>> since stack needs to hold generic type objects of type E ?

Only if you want to use a Stack that holds objects of class E (that is, if you really have a class named E). So, no, not likely.

What class of objects is the Stack meant to hold?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19682
    
  20

Well, if E is either a class, or a generic type of the class / method this code runs in, then it would be good.
John Laker
Greenhorn

Joined: Oct 01, 2010
Posts: 22
Rob Prime wrote:Well, if E is either a class, or a generic type of the class / method this code runs in, then it would be good.


yes, E is a generic type object
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help creating arraylist of stacks