I'm using the Arrays.asList().contains() method in my code, as shown in the top answer: How can I test if an array contains a certain value?, so I am going to use Arrays.asList() in the code.
However, the compiler rejects this following code. Is it because of using primitives for my primes array, rather than a reference type? I don't think so, due to autoboxing, but I just wanted to check.
import java.math.*;
import java.util.ArrayList;
import java.util.Arrays;
public class .... {
public static void main(String[] args) {
int[] primes = formPrimes(15);
ArrayList<Integer> primes1 = new ArrayList<Integer>(Arrays.asList(primes));
// Rest of code...
}
public static int[] formPrimes(int n) {
// Code that returns an array of integers
}
}
I get one error, a cannot find symbol error.
symbol : constructor ArrayList(java.util.List)
location: class java.util.ArrayList ArrayList primes1 = new ArrayList(Arrays.asList(primes));
Basically, I've got a function returning an array of integers, and I want to convert it into an array list, and I'm running into trouble with using the ArrayList constructor.