• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12149
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want something with a fixed size, what's wrong with an array?
 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic