Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:20:04+00:00 2026-06-05T09:20:04+00:00

I’m using the Arrays.asList().contains() method in my code, as shown in the top answer:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:20:06+00:00Added an answer on June 5, 2026 at 9:20 am

    Yes. Autoboxing does not apply to arrays, only to primitives.

    The error I get in eclipse is
    The constructor ArrayList<Integer>(List<int[]>) is undefined

    Thats because the constructor in ArrayList is defined as public ArrayList(Collection<? extends E> c). As you can see, it only accepts a subtype of Collection, which int is not.

    Just change your code to:

    public class .... {
        public static void main(String[] args) {
            Integer[] primes = formPrimes(15);
            ArrayList<Integer> primes1 = new ArrayList<Integer>(Arrays.asList(primes));
            // Rest of code...
        }
    
        public static Integer[] formPrimes(int n) {
            // Code that returns an array of integers
        }
    }
    

    and all should be well, assuming you return an Integer array from fromPrimes.

    Update
    From Andrew’s comments, and after peeking into the source of Arrays.asList:

    public static <T> List<T> asList(T... a) {
        return new ArrayList<T>(a);
    }
    

    So what is really happening here is that Arrays.asList(new int[] {}) would actually return a List<int[]>, unlike Arrays.asList(new Integer[] {}) which would return aList<Integer>. Obviously the ArrayList constructor will not accept a List<int[]>, and hence the compiler complains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.