aspose file tools*
The moose likes Beginning Java and the fly likes data structure of fixed size of 5 elements, each element has a variable number of integers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "data structure of fixed size of 5 elements, each element has a variable number of integers" Watch "data structure of fixed size of 5 elements, each element has a variable number of integers" New topic
Author

data structure of fixed size of 5 elements, each element has a variable number of integers

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 247
I want a data structure which has a fixed size of 5 elements.
Each element contains a variable number of integers.
Is the following code the best way to fullfill my requirement?
How to improve it?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11402
    
  16

If you want something with a fixed size, what's wrong with an array?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 247
fred rosenberger wrote:If you want something with a fixed size, what's wrong with an array?

Nothing wrong with an array, I am still trying to figure out how to use an array with ArrayList<Integer>.
The following has a compile time warning, which is the best solution.
How to fix it?
Type safety: The expression of type ArrayList[] needs unchecked conversion to conform to ArrayList<Integer>[]

The following will fail to compile:
Type mismatch: cannot convert from ArrayList<Integer> to ArrayList<Integer>[] ArrayListTest.java ArrayListTest/src


The following code will get java.lang.NullPointerException.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: data structure of fixed size of 5 elements, each element has a variable number of integers