In your example, it is because you can’t have a List of a primitive type. In other words, List<int>
is not possible.
You can, however, have a List<Integer>
using the Integer
class that wraps the int
primitive. Convert your array to a List
with the Arrays.asList
utility method.
Integer[] spam = new Integer[] { 1, 2, 3 }; List<Integer> list = Arrays.asList(spam);
Related Posts:
- Convert list to array in Java [duplicate]
- Converting array to list in Java
- List of Arrays in Java
- How to initialize an array in Java?
- Initialize part of an array in java
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - How do I declare and initialize an array in Java?
- Sort an array in Java
- What’s the simplest way to print a Java array?
- Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
- What’s the simplest way to print a Java array?
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- Converting String to “Character” array in Java
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- Create ArrayList from array
- Convert Set to List without creating new List
- How to split a String by space
- Print ArrayList
- Make copy of an array
- How to create a sub array from another array in Java?
- How to fix array index out of bounds error?
- Working with a List of Lists in Java
- Array ArrayList python equivalent
- Double array initialization in Java
- Java – Best way to print 2D array?
- java Arrays.sort 2d array
- I want to declare an empty array in java and then I want do update it but the code is not working
- method in class cannot be applied to given types
- How to convert an ArrayList containing Integers to primitive int array?
- stale element reference: element is not attached to the page document
- Error: can only iterate over an array or an instance of java.lang.Iterable
- Where is Java’s Array indexOf?
- Convert an integer to an array of characters : java
- How to efficiently remove duplicates from an array without using Set
- Print ArrayList
- Convert array of strings into a string in Java
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- How to create an empty array?
- Will Arrays.sort() increase time complexity and space time complexity?
- How can I concatenate two arrays in Java?
- Java – Best way to print 2D array?
- What is the difference between a null array and an empty array?
- How to initialize List
object in Java? - Is there a concurrent List in Java’s JDK?
- “Instantiating” a List in Java? [duplicate]
- method in class cannot be applied to given types
- How can I create an Array of ArrayLists?
- Create a List of primitive int?
- Are arrays passed by value or passed by reference in Java?
- How to print out all the elements of a List in Java?
- Shifting array to the right – homework
- Random shuffling of an array
- How to convert int[] to Integer[] in Java?
- what is Ljava.lang.String;@
- Type List vs type ArrayList in Java
- “Cannot create generic array of ..” – how to create an Array of Map
? - Convert String to int array in java
- “Actual or formal argument lists differs in length”
- Java Comparator class to sort arrays
- Resize an Array while keeping current elements in Java?
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- local variables referenced from an inner class must be final or effectively final
- Bank Account Java Program
- What is the default initialization of an array in Java?
- Java, Shifting Elements in an Array
- Counting an Occurrence in an Array (Java)
- How to make an array of arrays in Java
- Empty an array in Java / processing
- Java, Simplified check if int array contains int
- Error: Generic Array Creation
- Add String Array to ArrayList
- Java Array Sort descending?
- Java read file and store text in an array
- (Java) Tic-Tac-Toe game using 2 dimensional Array
- Incompatible types List of List and ArrayList of ArrayList
- int cannot be converted to int []
- Finding the size of a char array in Java
- Any way to declare an array in-line?
- Getting the array length of a 2D array in Java
- Get only part of an Array in Java?
- Checking to see if array is full
- How to use ArrayUtils for array of objects, it doesn’t delete the content of an array
- Error array dimension missing
- Printing char arrays in Java
- Fill an array with random numbers [duplicate]
- Create a two dimensional string array anArray[2][2]
- Printing array elements with a for loop
- How do I convert this for loop into a while loop?
- How do I initialize a byte array in Java?
- How do you set one array’s values to another array’s values in Java?
- java.lang.ArrayIndexOutOfBoundsException: 0
- How to increase the size of an array in Java?
- How to get rows and columns count of a 2D array in Java?
- convert string to arraylist
in java - How do I join two lists in Java?
- When to use a Map instead of a List in Java?
- Multidimensional Arrays lengths in Java