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

  • Home
  • SEARCH
  • 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 6743575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:58:39+00:00 2026-05-26T11:58:39+00:00

I have this method which takes a varargs of Strings, creates a List out

  • 0

I have this method which takes a varargs of Strings, creates a List out of it, and then tries to remove the first element of the list.

public void importFrom(String... files) {
    List<String> fileList = Arrays.asList(files);

    String first = fileList.remove(0);
    // other stuff
}

But as soon as remove gets called, an UnsupportedOperationException is thrown. My guess is that the return List-Type does not support the remove method. Am I correct? What alternatives do I have?

  • 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-05-26T11:58:39+00:00Added an answer on May 26, 2026 at 11:58 am

    Arrays.asList only provides a thin wrapper around an array. This wrapper allows you to do most operations on an array using the List API. A quote from the JavaDoc:

    Returns a fixed-size list backed by the specified array. […]
    This method acts as bridge between array-based and collection-based APIs […]

    If you really want to remove something, then this might work:

    List<String> realList = new ArrayList<String>(Arrays.asList(stringArray));
    

    This one creates a real ArrayList (which supports remove) and fills it with the contents of another list which happens to be the wrapper around your String[].

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

Sidebar

Related Questions

I have a thread, within this thread I call a method which takes a
I have a webservice method which takes an Id and then will kick off
I have an extension method which takes in two list and compares them for
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have this method Verify_X which is called during databind for a listbox selected
I have this code: s(x => x.Open()); s is a method which calls one
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I have a method, which uses random samples to approximate a calculation. This method
I have an interface called Dictionary which has a method insert() . This interface
I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true); . So this

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.