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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:47:21+00:00 2026-06-13T20:47:21+00:00

I need to create a custom class that extends java.util.LinkedHashMap and takes String as

  • 0

I need to create a custom class that extends java.util.LinkedHashMap and takes String as key and String as value and has a no-arg constructor that pre-populates this map with initial values.

I am stuck at the first task – how to extend the LinkedHashMap in such a way that instead of generic arguments it accepts only?

I tried this, (not working)

import java.util.LinkedHashMap;

@SuppressWarnings("serial")
public class MyMenu<String, String> extends LinkedHashMap<String, String> {


    public MyMenu(){
        this.put("index.jsp", "Home Page");
    }
}
  • 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-13T20:47:23+00:00Added an answer on June 13, 2026 at 8:47 pm

    All you need is:

    import java.util.LinkedHashMap;
    
    @SuppressWarnings("serial")
    public class MyMenu extends LinkedHashMap<String, String> {
    
        public MyMenu(){
            this.put("index.jsp", "Home Page");
        }
    }
    

    Remove <String, String> from your class name and it will work. You are creating a class which is extending LinkedHashMap<String, String> so your class is already a Map which takes String as a key and String as a value. If you want to create your own generic class then you have to do like this:

    Create a class for e.g.:

    public class MyMenu<K, V> { ... }
    

    and then extend that class:

    public class SomeMyMenu extends MyMenu<String, String> { ... }
    

    In that case you will have to specify the key and value for your class in order for SomeMyMenu class use the key and value as String. You can read more about generics here.

    But more efficient way to do what you want is to create some final class and declare the map in it like this:

    public static final LinkedHashMap<String, String> MAP = new LinkedHashMap<String, String>() {{
        put("index.jsp", "Home Page");
    }};
    

    And to get the values from your map use:

    SomeClass.MAP.get("Some Key");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I need to create a class that extends JDialog , to remove JDialog
I need to create a class with exactly the same methods as java.lang.String .
I need to create a custom view, which extends RelativeLayout and simply needs to
I need to create a custom constraint annotation which can access the value of
I have my own custom LinkedList class that has a pointer to the first
I need to create a global Arraylist consisting Instances of my custom class 'Book'
I want to create a custom control that extends a built-in control and then
I am trying to create a button that has a custom shape (hexagon), but
I need to create a Symfony 2 custom class constraint validator , to validate
I'm attempting to create a custom JButton that has interchangeable skin components. Using CardLayout

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.