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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:06:28+00:00 2026-05-30T00:06:28+00:00

I am new to Java and i am currently rewriting a Perl code in

  • 0

I am new to Java and i am currently rewriting a Perl code in Java.
In Perl i have a Hash of Hash like

$hashref->{index1}->{index2}->{index3} = $value;

In this i store the index1 , index2 , and index3 in 3 separate hashes along with above hash.
Also Index1 and index2 are of type long and index3 is String.

Now i want to rewrite the similar stuff in Java.
So i came up with 2 ways

1)HashMap<Long, HashMap<Long ,HashMap<String,String> >>
2)HashMap<String, String> //In this approach i concatenate index1,index2 and index3 using _ and make a single string

I want to know which way will be efficient as max of 100 keys for index1, 300 keys for index2 and 700 keys for index3 is possible.

  • 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-05-30T00:06:31+00:00Added an answer on May 30, 2026 at 12:06 am

    First, let’s discuss #2

    • It doesn’t work 100% of the time due to possible ambiguity if the index strings can contain the separator character (“_”):

      E.g. consider 3 sets of indexes: (“12”, “13_13” and “14”) and (“12_13”, “13” and “14”). They both produce the same concatenated key.

    • It doesn’t allow straightforward processing of the 2-d and 3-d level hashes as data structures easily.

      E.g. you can not easily do Java equivalent of “keys %{$hash->{index1}}” – find all the keys for a hash of second level stored under index1. It’s doable, but much harder. Or “delete $hash->{index1}“.

    If these 2 considerations don’t bother you, using a concatenated key for 1-level HashMap is fine.

    If they do, you need to do #1 – a fairly robust implementation was posted on SO previously:
    ” Java equivalent of Perl's hash ” . Please note that such implementation is NOT trivial, and therefore your alternate approach of concatenated 1 level of indexes is a very good alternative.

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

Sidebar

Related Questions

I am currently calling the following line of code: java.net.URL connection_url = new java.net.URL(http://<ip
I'm new to Java and currently involve in a project, this problem confuses me
I'm fairly new to Java. Currently trying to have the filename given in args[]
I'm currently doing something like this; import java.util.*; public class TestHashMap { public static
Sorry, I'm new to Java, so this question might be unclear. I have been
we are currently working on a new web application using Java and MySql. We
I'm new to Eclipse and am using it currently to play with Java EE.
I'm currently integrating some new classes into an existing application. I have a JDialog
I'm currently making a small program to teach me some new Java, and I'm
I'm new to JAVA and I'm currently trying out both Netbeans and Eclipse. I'm

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.