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

The Archive Base Latest Questions

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

I am new on Java and Android. I want to understand the following line:

  • 0

I am new on Java and Android. I want to understand the following line:

List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();

My doubt is: it is declared an object called listMap, which is of the type List of Map, right? But it is instantiated as an ArrayList. Sorry for the simple question, but Why is this possible?

ps1: I know List is an interface, so I can’t instantiate an object of an interface type.

ps2: I can declare listMap as being of the ArrayList type. What is the advantage of declare it as a List.

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

    ps1: I know List is and interface, so I can’t instantiate and object of its type.

    List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
    

    You are right, List is an Interface hence you will not be able to instantiate an Interface. You need to use some implementing class of the interface to instantiate. ArrayList is an implementation class of interface List and being used in the able statement.

    ps2: I can declare listMap as being of the type ArrayList. What is the advantage of declare it as a List.

    You can always, use ArrayList in the left side as well i.e.

      ArrayList<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
    

    Advantage of using Interface: If you want to use your variable object(listMap) across the classes then better to use the Interface as type, but if your variable object (lsitMap) locally within your program locally, then I don’t think there is any added advantage.

    Now you will think about Map, which is again an Interface. Please note that, you are not instantiating the Map object through above statement. You are just mentioning that your listMap list will contain the element of Map type.

    Again when you will try to instantiate elements to add in the listMap, you will need an implementation class of Map interface e.g HashMap as below:

       List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
    
       Map<String, String> lsitMapElement1 = new HashMap<String, String>();
       lsitMapElement1.put("key1", "value1");
       listMap.add(lsitMapElement1 );
    
       Map<String, String> lsitMapElement2 = new HashMap<String, String>();
       lsitMapElement2.put("key2", "value2");
       listMap.add(lsitMapElement2);
    

    Hope this makes things clear.

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

Sidebar

Related Questions

I'm still new to programming/Java/Android so I'm trying to understand everything I do and
I'm completely new to Java/Android and am stuck with listviews. What I want is
I want to start app-development for Android. I'm not new to java but the
I'm new to Android and Java. I want to create an application with one
I am new to Android and Java Programming and I want to ask if
I'm new to Java and Android development and I want to ask what are
Begginer android programer, I want add and remove item from String list when user
I'm new to Java/Eclipse/Android, so this is probably an easy (if not stupid) question:
I'm fairly new to Java and Android programming in general but I would like
I am also new to Java and Android Development, been making a simple game

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.