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 data structure of choice. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "data structure of choice." Watch "data structure of choice." New topic
Author

data structure of choice.

Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
I'm trying to implement a structure that is akin to a 2-d array, but each column will get resized alot. I was thinking that a a list of lists would be good, but am not sure how to implement that in java. Array list seems like the way to go.
I think I can do an array of lists, which will work, but is that acceptable practice? Lasty, I can't figure how to do explicit typing with ArrayList. here is some sample code:


in this line, "nums[i] = new ArrayList();",
how could I specify the type?

this declaration is what I keep wanting to do:
"nums[i] = new ArrayList<int>(); " but it doesn't compile. (unexpected type)
compiled on blueJ
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
the problem has mutated, looks like ArrayList is the way to go for resizing arrays alot, but I can't compile an ArrayList without a warning for unchecked call, like so:


compile warnings are:
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

In your first post, "nums[i] = new ArrayList<int>();" doesn't compile because the type for ArrayList cannot be primitive. If you use Integer in place of int, it should work (with Java 5.0 autoboxing and unboxing between primitives and wrapper objects).

In your second post, if your ArrayLists are holding objects of type Icon, then you probably want "new ArrayList<Icon>();".

(Yes, ArrayList implements the interface java.util.List.)
[ August 22, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
Thank you for your reply.
I still get the warnings about unchecked calls, though. what is that about, if I have explicitly given the list a type?
thanks,
Jeff
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jeff Finn:
... I still get the warnings about unchecked calls, though. what is that about, if I have explicitly given the list a type? ...

Can you post your code?
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
I don't get the warning anymore. I think there was an issue with my project space and the IDE I was using, BlueJ. I started a new project in a new workspace, and the issues went away . here is a copy of the code in it's current form, please don't judge me for bad programming, I'm just trying to make it work. On the other hand, critique is welcome...



Can anyone suggest a more reliable IDE that isn't as complex as eclipse or netbeans? I would like to concentrate on learning Java, and big IDEs only complicate the issue.
Patrick van Zandbeek
Ranch Hand

Joined: Aug 17, 2005
Posts: 37
On IDE, my humble opinion is that for learning Java you shouldn't really use one. What works wonders though is an editor that provides syntax colouring.

check out the following two for instance:


Textpad - nice shareware editor, very stable. You can download syntax colour files for this one, just place them in textpad's system folder

jEdit - Free! Java based programmer's text editor. Very nice too with lot's of features, but slightly less user friendly.

both are great for learning Java and there are more programs like them out there, but these are two I really like.


u is a letter, not a word.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jeff Finn:
...I would like to concentrate on learning Java, and big IDEs only complicate the issue.

Correct. Don't use an IDE to learn Java.
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
what is the proper way to declare this statement to avoid warnings about unchecked/unsafe operations?


I initialize this with the loop:


this won't compile:

says generic array creation.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
You cannot create an array of a paramterized type unless it is the unbounded wildcard (which you don't want). Use a List<List> if you really have to; or rewrite collections properly if you have the time.


Tony Morris
Java Q&A (FAQ, Trivia)
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
what are you suggesting by rewrite collections properly? Use a better data structure? What I want is something like 2-d array where each column is resized frequently. an array of lists seemed nice, buy that doesn't seem doable.
thanks,
Jeff
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
so, to do what I wanted, I made a class IconList that extends ArrayList.
then I made an array of type IconList, like so
IconList [] theBigList = new IconList[6]; since this array index will be fixed. is this OK?
Jeff
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
I mean do not use java.util.* and use a third party, or if you wish to do it yourself, so be it.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jeff Finn:
so, to do what I wanted, I made a class IconList that extends ArrayList. then I made an array of type IconList...

Couldn't you just use an ArrayList in place of the array? That is, an ArrayList that contains ArrayLists (considering that a "2-d" array in Java is just an array that contains arrays). Then you should be able to use type parameters.
Jeff Finn
Greenhorn

Joined: Aug 07, 2005
Posts: 13
I did try the list of lists thing, and it compiled, but I can't remember If I had trouble with the unchecked thing. The thing is, for reasons related to the program, I am synching the column index and the x-value for an Icon I am drawing. So It is nice to have an index that is always there. I am working on some other parts of the code right now, but when I have that squared away, I will print the code and show you what I am doing.
 
Don't get me started about those stupid light bulbs.
 
subject: data structure of choice.
 
Similar Threads
K&B generics doubt
sort number
Sudoku solver help (not brute force)
Multidimensional ArrayList
Three Dimensional ArrayList?