an Array of ArrayLists in Java 5

G

Gary Newell

Hi -

I need some Java 5 help. The following code snippet worked fine in Java
1.4.2.

I'm setting up an array of ArrayLists. Each ArrayList contains Doubles.
The following code is generating a compiler time warning.

code:
- - - - - - - - - - - - - - - - - - - - - - - - - - -
import java.util.*;

public class arrayOfArrayLists {

public static void main(String args[]) {

ArrayList arrayListDoubles[] = new ArrayList [ 5 ];

for( int j=0; j<arrayListDoubles.length; j++ ) {
arrayListDoubles[ j ] = new ArrayList<Double> ();
}

// start loading values into the first arraylist
arrayListDoubles[0].add( new Double( "100" ) );
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - - -
compiler warning:
- - - - - - - - - - - - - - - - - - - - - - - - - - -
C:\temp>javac -d . -Xlint:unchecked *.java
arrayOfArrayLists.java:13: warning: [unchecked] unchecked call to add(E) as
a member of the raw type java.util.ArrayList
arrayListDoubles[0].add( new Double( "100" ) );
- - - - - - - - - - - - - - - - - - - - - - - - - - -

Any idea how to get each of the ArrayLists in the Array to be expecting
Doubles?

Thanks!!

Gary
 
R

Ryan Stewart

[...]
ArrayList arrayListDoubles[] = new ArrayList [ 5 ]; [...]
arrayListDoubles[0].add( new Double( "100" ) ); [...]
- - - - - - - - - - - - - - - - - - - - - - - - - - -
C:\temp>javac -d . -Xlint:unchecked *.java
arrayOfArrayLists.java:13: warning: [unchecked] unchecked call to add(E)
as
a member of the raw type java.util.ArrayList
arrayListDoubles[0].add( new Double( "100" ) );
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Specify a type for the ArrayList:
ArrayList<Double>[] arrayListDoubles = new ArrayList<Double>[5];
 
G

Gary Newell

Ryan -

Both of these generate compile time errors:
ArrayList<Double>[] arrayListDoubles = new ArrayList<Double> [ 5 ];
and
ArrayList<Double> arrayListDoubles[] = new ArrayList<Double> [ 5 ];

Errors (respectively):
C:\temp>javac arrayOfArrayLists.java
arrayOfArrayLists.java:7: generic array creation
ArrayList<Double>[] arrayListDoubles = new ArrayList<Double>
[ 5 ];
^
1 error

C:\temp>javac arrayOfArrayLists.java
arrayOfArrayLists.java:7: generic array creation
ArrayList<Double> arrayListDoubles[] = new ArrayList<Double>
[ 5 ];
^
1 error


Any ideas?

Gary



Ryan Stewart said:
[...]
ArrayList arrayListDoubles[] = new ArrayList [ 5 ]; [...]
arrayListDoubles[0].add( new Double( "100" ) ); [...]
- - - - - - - - - - - - - - - - - - - - - - - - - - -
C:\temp>javac -d . -Xlint:unchecked *.java
arrayOfArrayLists.java:13: warning: [unchecked] unchecked call to add(E)
as
a member of the raw type java.util.ArrayList
arrayListDoubles[0].add( new Double( "100" ) );
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Specify a type for the ArrayList:
ArrayList<Double>[] arrayListDoubles = new ArrayList<Double>[5];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top