This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data structure of choice.

 
Jeff Finn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jeff Finn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Finn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic