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 do I determine whether an array contains a particular value in Java?
- How to initialize an array in Java?
- Initialize part of an array in java
- How to avoid “ConcurrentModificationException” while removing elements from `ArrayList` while iterating it? [duplicate]
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - How to split a string into an array in Bash?
- 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 string to date conversion
- How to print elements in a vector c++
- Converting String to “Character” array in Java
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- TypeScript Objects as Dictionary types as in C#
- Create ArrayList from array
- string to string array conversion in java
- Data type not understood while creating a NumPy array
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- What is the difference between String[] and String… in Java?
- Convert Set to List without creating new List
- How do I reverse an int array in Java?
- Are vectors passed to functions by value or by reference in C++
- How do I declare a 2d array in C++ using new?
- How to split a String by space
- Python List vs. Array – when to use?
- “error: assignment to expression with array type error” when I assign a struct field (C)
- Print ArrayList
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Getting “conflicting types for function” in C, why?
- Print ArrayList
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- Make copy of an array
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- How to create a sub array from another array in Java?
- Form submission: PHP S_SESSION statements within a foreach loop
- How to split a string into an array in Bash?
- How to fix array index out of bounds error?
- Array Size (Length) in C#
- Getting “conflicting types for function” in C, why?
- Array ArrayList python equivalent
- Python: Array v. List
- Double array initialization in Java
- Array of arrays (Python/NumPy)
- 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
- Calculating Standard Deviation & Variance in C++
- What is the difference between String[] and String… in Java?
- 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?
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- Convert an integer to an array of characters : java
- What does ** do in C language?
- How to efficiently remove duplicates from an array without using Set
- Correct way of looping through C++ arrays
- When will the worst case of Merge Sort occur?
- 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
- TypeError: list indices must be integers or slices, not str
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- How to create an empty array?
- Finding the max/min value in an array of primitives using Java
- Will Arrays.sort() increase time complexity and space time complexity?
- How can I concatenate two arrays in Java?
- 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?
- what does .space do in mips?
- “Instantiating” a List in Java? [duplicate]
- method in class cannot be applied to given types
- How do I remove an array item in TypeScript?
- How can I create an Array of ArrayLists?