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 8667217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:54:48+00:00 2026-06-12T17:54:48+00:00

I start learning the Java generic collection using Deitel Harvey book – but I

  • 0

I start learning the Java generic collection using Deitel Harvey book – but I am facing a difficulty understanding the three line of codes below – Do all of them perform the same operation on by intializing and adding the relevant values of array ( colors ) to the LinkList variable (list1). How does the second method and third method works – I am having a bit difficulty understanding how Arrays can viewed as a list.. As I know arrays are not dynamic data structure, they have fixed sized length, adding/ removing elements on array can not be done on running time comparing to Lists in general.

String[] colors = { "black", "white", "blue", "cyan" };
List< String > list1 = new LinkedList< String >();

// method 1 of initalizing and adding elments to the list
for (String color : colors)
    list1.add(color);

// method 2 of initializing and adding elements to the list
List< String > list1 = new LinkedList< String > (Arrays.asList(colors));

// method 3 of initializing and adding elements to the list
List< String > list1 = Arrays.asList(colors);

Please help me understand my queries above, don’t judge me as I am still new to this.
Thank you, Sinan

  • 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-12T17:54:49+00:00Added an answer on June 12, 2026 at 5:54 pm

    Every time you are interested in implementation you can look into certain method. For example, by press Ctrl+left mouse button onto method or class.

    // method 2 of initializing and adding elements to the list
    List<String> list1 = new LinkedList<String> (Arrays.asList(colors));
    

    This code leads to:

    List<String> list1 = new LinkedList<String> (new ArrayList<String>(colors));
    

    In constructor of ArrayList:

    ArrayList(E[] array) {
                if (array==null)
                    throw new NullPointerException();
            a = array;
        }
    

    the actual array is copied to encapsulated private array field(link is copied).

    Then in constructor of LinkedList:

    public LinkedList(Collection<? extends E> c) {
        this();
        addAll(c);
        }
    

    Every element of passed collection is added to the LinkedList.

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

Sidebar

Related Questions

I start learning some java concurrency concept ans put in use. But one of
I'm learning Java as I complete CodingBat exercises, and I want to start using
I wanted to start learning java but Eclipse is giving me some trouble. First
I am learning Java and trying to run some examples using Java web start.
I plan to start learning a Java web framework (I love the Java API)
I want to start learning more about using SWIG and other methods to interface
Which one should I install when I want to start learning Java? I'm going
I'd like to start learning multithreading in C++. I'm learning it in Java as
I'm learning Java right now but I'm wondering if there is a hierarchy of
I have recently started having a need to start learning Java Script. My application

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.