Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type ArrayList is not generic; it cannot be parameterized with arguments <Integer>

I am trying to complete a JCF array list, and it compiled just fine 30 minutes ago, but now I am receiving the error "The type ArrayList is not generic; it cannot be parameterized with arguments ". I have tried a few things to figure it out, but I am at a loss. Here is the code:

import java.util.*;

/**
 * Class to test the java.util.ArrayList class.
 */
public class Main
{

    public static void main(String[] args)
    {
        Main myAppl = new Main();

    }

    public Main()
    {
        ArrayList<Integer> numbers = new ArrayList<Integer>();

        //list creation
        for (int i = 0; i < 10; i++)
            numbers.add((int) (Math.random() * 100));

        System.out.println("List of numbers:");
        System.out.println(numbers);

        Scanner in = new Scanner(System.in);
        System.out.print("Please, enter an int value: ");
        int x = in.nextInt();

        if (numbers.contains(x))
            System.out.println("Found!");
        else
            System.out.println("Not found!");
    }
}
like image 312
Ryel Avatar asked Feb 13 '26 02:02

Ryel


1 Answers

2 possibilities:

  1. You are using some mysterious ArrayList from a 3rd party package rather than java.util.ArrayList; or

  2. Your compiler settings is pre-1.5 or your effective JDK is pre-1.5 so generic wasn't available.

like image 176
Alex Suo Avatar answered Feb 14 '26 16:02

Alex Suo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!