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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:01:29+00:00 2026-06-14T10:01:29+00:00

I can not initialize a List as in the following code: List<String> supplierNames =

  • 0

I can not initialize a List as in the following code:

List<String> supplierNames = new List<String>();
supplierNames.add("sup1");
supplierNames.add("sup2");
supplierNames.add("sup3");
System.out.println(supplierNames.get(1));

I face the following error:

Cannot instantiate the type List<String>

How can I instantiate List<String>?

  • 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-14T10:01:31+00:00Added an answer on June 14, 2026 at 10:01 am

    If you check the API for List you’ll notice it says:

    Interface List<E>
    

    Being an interface means it cannot be instantiated (no new List() is possible).

    If you check that link, you’ll find some classes that implement List:

    All Known Implementing Classes:

    AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector

    Some of those can be instantiated (the ones that are not defined as abstract class). Use their links to know more about them, I.E: to know which fits better your needs.

    The 3 most commonly used ones probably are:

     List<String> supplierNames1 = new ArrayList<String>();
     List<String> supplierNames2 = new LinkedList<String>();
     List<String> supplierNames3 = new Vector<String>();
    

    Bonus:
    You can also instantiate it with values, in an easier way, using the Arrays class, as follows:

    List<String> supplierNames = Arrays.asList("sup1", "sup2", "sup3");
    System.out.println(supplierNames.get(1));
    

    But note you are not allowed to add more elements to that list, as it’s fixed-size.

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

Sidebar

Related Questions

How can we initialize an IList in Silverlight? For exa following is not permitted
I have the following code in C#: IList <string > myList = null; myList.Add(temp);
My class contains LOT_SIZE constant which can not be changed. But I can initialize
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
I can not get to make this comparison in this simple code error ..
I have the following code snippet.. I get the error Expected identifier, string or
Consider the following code MyClass <- setRefClass(MyClass, fields = list(body = vector), methods =
I'm wondering if this code ... StringBuilder sb = new StringBuilder(Please read the following
Can not parse json using this var res = eval('(' + response + ')');
I can not directly user $('commentbody') because there are many comments and selection needs

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.