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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:30:27+00:00 2026-06-18T03:30:27+00:00

Class Test is my separate class which has two field of String and Float

  • 0

Class Test is my separate class which has two field of String and Float type, I am using this class with List Collections which will be finally populated as values into HashMap.

But when I try to populate the Map with a key and the List objects (values) into the map, Java does not seem to accept it as it is not valid syntax:

ArrayList <Test> list = new ArrayList <Test> ();

Map<Integer, ArrayList <Test>> mp = new HashMap<Integer, ArrayList <Test>>();  

list.add(new Telephone ( 0.9 , "A"));
list.add(new Telephone(5.1 , "A"));

mp.put(0,list.get(0)); // this Does Not work :(, it should work

Output:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method put(Integer, ArrayList<Telephone>) in the type  
   Map<Integer,ArrayList<Telephone>> is not applicable for the arguments 
   (int,   Telephone) at Main.main(Main.java:64)
  • 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-18T03:30:28+00:00Added an answer on June 18, 2026 at 3:30 am

    Going by your requirement you told in comments and question above I think you need following syntax for Map declaration:

    Map<Integer,Test> mp = new HashMap<Integer,Test>();
    

    EDIT

    OK here is the Edit:

    ArrayList<Test> list = new ArrayList<Test>();
    Map<Integer,ArrayList<Test>> mp = new HashMap<Integer,ArrayList<Test>>();
    list.add(new Test(0.1,"A"));
    list.add(new Test(0.2,"B"));
    mp.put(1,list);
    

    and if you again want to put more Test objects at key 1 then do as follows:

    List<Test> value = mp.get(1);
    value.add(0.3,"c");
    value.add(0.5,"E");
    
    mp.put(1,value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a test php extension, which will provide a test class.
class Test { public static void main(String[] args) throws Exception { Test t =
class Test { public: SOMETHING DoIt(int a) { float FLOAT = 1.2; int INT
class Test { ; int x; }; Is this perfectly legal and portable?
class Test { enum{}; ... }; Is this empty enum definition portable? Compiles in
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){
I've created a class library which has a method to query for open ports,
I've got a project which has in it a protocol, a class implementing that
I have a separate class library that I'm using for all of my unit

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.