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);
See this code run live at IdeOne.com.
Related Posts:
- Converting array to list in Java
- Working with a List of Lists in Java
- Convert list to array in Java [duplicate]
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- How to convert jsonString to JSONObject in Java
- what does “>>>” mean in java?
- How to convert List
to int[] in Java? - How to convert int[] into List
in Java? - What is a list in Bash?
- In Java, how to append a string more efficiently?
- ow to create a histogram in java
- List of Arrays in Java
- Java ArrayList for integers
- java.lang.ArrayIndexOutOfBoundsException: 4 Error
- Convert ArrayList
to java.util.List [closed] - Java says this method has a constructor name
- Using the Pythagorean theorem with Java
- TypeError: list indices must be integers or slices, not str
- 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 to split a string into an array in Bash?
- Sort an array in Java
- What’s the simplest way to print a Java array?
- What’s the simplest way to print a Java array?
- How to print elements in a vector c++
- Create ArrayList from array
- What is the difference between String[] and String… in Java?
- Convert Set to List without creating new List
- Are vectors passed to functions by value or by reference in C++
- “error: assignment to expression with array type error” when I assign a struct field (C)
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Print ArrayList
- Make copy of an array
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- How to fix array index out of bounds error?
- Python: Array v. List
- Double array initialization in Java
- Array of arrays (Python/NumPy)
- Java – Best way to print 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
- Calculating Standard Deviation & Variance in C++
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- What does ** do in C language?
- 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?
- How do I create an array of strings in C?
- 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?
- Are arrays passed by value or passed by reference in Java?
- What does << mean in Ruby?
- How to print out all the elements of a List in Java?
- lists and arrays in VBA
- Shifting array to the right – homework
- what is Ljava.lang.String;@
- Type List vs type ArrayList in Java
- Convert String to int array in java
- “Actual or formal argument lists differs in length”
- Bubble sort algorithm in MIPS
- Resize an Array while keeping current elements in Java?
- How to sort an array of objects in Java?
- Error: unsupported use of matrix or array for column indexing
- Using multiple variables in a for loop in Python
- Weighted random selection from array
- How to make an array of arrays in Java
- numpy-equivalent of list.pop?
- Java, Simplified check if int array contains int
- Error: Generic Array Creation
- How to create a numpy array of lists?
- 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 []
- 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 sort an array in Bash
- How to use ArrayUtils for array of objects, it doesn’t delete the content of an array
- Printing char arrays in Java
- Fill an array with random numbers [duplicate]
- 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 to declare and use 1D and 2D byte arrays in Verilog?
- Difference between char *argv[] and char **argv for the second argument to main()
- Dynamic vs static array in c
- How to get rows and columns count of a 2D array in Java?
- When to use a Map instead of a List in Java?
- Print array elements on separate lines in Bash?
- What is the best way to delete a value from an array in Perl?
- variably modified array at file scope in C
- Numpy matrix to array