I don't know where did I do wrong here, but it is a compiler error. I was try to create an Arraylist that can store the double value. For some reason, I got a compiler error when I try to create an Arraylist. By the way, the assignment specifically ask to use arraylist from java utility library.

Here is the code:

import java.util.Scanner;
import java.util.ArrayList;
public class StudentList
{	
	
	public static void pause() 
	{ 
		try 
		{ 
			System.out.print("Press <Enter> to continue..."); 
			System.in.read(); 
		} 
		catch (Exception e)
		{
			System.err.printf("Error %s%c\n",e.getMessage(),7);
		}
	}
	
	public static void main(String[] args)
	{
		
		ArrayList< String > studentFName = new ArrayList< String >();
		ArrayList< String > studentLname = new ArrayList< String >();
		ArrayList< String > major = new ArrayList< String >();
		ArrayList< double > gpa = new ArrayList< double >();
		
		
		Scanner keyBd = new Scanner( System.in );
		char selection;

		do{
			System.out.println("\n--------------");
			System.out.println("1. Add Student");
			System.out.println("2. Remove Studnet");
			System.out.println("3. Find Studnet");
			System.out.println("4. Display Studnet");
			System.out.println("5. Display All Studnet");
			System.out.println("6. Exit\n");
			System.out.print  ("Selection: ");

			selection = keyBd.next().charAt(0);
						
			switch (selection){
				case '1':
					
					pause();
					break;
				case '2':
					pause();
					break;
				case '3':
					pause();
					break;
				case '4':
					pause();
				case '5':
					pause();
					break;
				case '6':
					break;
				default :
					
					System.out.println("Invalid Selection");
			}//end switch

		}while( selection != '6');
		
		

	}//end main()

}

The compiler error message is
StudentList.java:25: error: unexpected type
ArrayList< double > gpa = new ArrayList< double >();
^
required: reference
found: double
StudentList.java:25: error: unexpected type
ArrayList< double > gpa = new ArrayList< double >();
^
required: reference
found: double
2 errors


Thank you so much.

You cannot use primitive type like int, double, float etc with Collection, you need to to use wrapper classes like Integer, Double etc

So if I declare my arraylist like this would be fine?

ArrayList <Double> rrr = new ArrayList<Double>();

So if I declare my arraylist like this would be fine?

ArrayList <Double> rrr = new ArrayList<Double>();

Why don't you try and tell me :)

I actually tried it before, it actually works. I just want to make sure it is not an accident.
Thank you though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.