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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:42:04+00:00 2026-06-05T10:42:04+00:00

I have some map with values: private static Map<String, Long> hodnotyUdaju = new HashMap<String,

  • 0

I have some map with values:

private static Map<String, Long> hodnotyUdaju = new HashMap<String, Long>();

static {
    hodnotyUdaju.put("a", 1L);
    hodnotyUdaju.put("b", 2L);
    hodnotyUdaju.put("b", 4L);
    hodnotyUdaju.put("d", 8L);
    hodnotyUdaju.put("e", 16L);
    hodnotyUdaju.put("f", 32L);
    hodnotyUdaju.put("g", 64L);
    hodnotyUdaju.put("h", 128L);
    hodnotyUdaju.put("i", 256L);
    hodnotyUdaju.put("j", 512L);
    .
    .
    .
}

and method which convert set of value to long

public static long bitovaHodnotaSeznamuUdaju(Set<String> udaje) {
    long bitovaHodnota = 0;

    for (String udaj : udaje) {
        Long tmp = hodnotyUdaju.get(udaj);
        if (tmp != null)
            bitovaHodnota += tmp;
    }

    return bitovaHodnota;
}

how I can implement this method vice versa ? I need from long to create set set of String

UPDATE

methos should looks like:

public static Set<String> bin2Udaje(long binUdaje) {
    Set<String> udaje = new HashSet<String>();
    for (Map.Entry<String, Long> entry : hodnotyUdaju.entrySet()) {
        if (udaje some operation entry.getValue() ) {
            udaje.add(entry.getKey());
        }
        return udaje;

    }
}
  • 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-05T10:42:07+00:00Added an answer on June 5, 2026 at 10:42 am

    It sounds like you should really be using an Enum for this instead of a map. For example, while you’re guaranteed to use values 1, 2, 4, 8… you’ll end up with an unambiguous answer – but doing that on a general map won’t work.

    I would suggest you use an enum which has an extra value for the string if you need it, and you can use 1L << value.ordinal() to get a long value if you really want. To represent a general set of these values, however, you can simply use EnumSet.

    If this isn’t appropriate, please give us more information.

    EDIT: If you really want to stick to your existing structure, you could use:

    public static Set<String> valueToKeySet(long value) {
        Set<String> keys = new HashSet<String>();
        for (Map.Entry<String, Long> entry : hodnotyUdaju.entrySet()) {
            if ((value & entry.getValue()) != 0) {
                keys.add(entry.getKey());
            }
        }
        return keys;
    }
    

    This will give unexpected results if your map doesn’t only contain single-bit-set values.

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

Sidebar

Related Questions

I have for instance this Map: Map<String, Integer> map = new HashMap<String,Integer>(); than I
I have a Struts form which contains a Map: private Map<Long, String> questionAnswers =
I have some code: in_msg.updateComments.map{|c| c.values}.each do |comment| ... end where in_msg.updateComments is a
let's say I have std::map< std::string, std::string > m_someMap as a private member variable
I have a map like this: private Map<String, List<List<String>>> someMap; private List<List<String>> someList1; private
I have a Google V3 map which uses steetView and some map markers. The
I have an XML file that I would like to map some attributes of
I have map with multiple different colors markers with some info window. Everything works
I have a collsion map, and some places that I want to be light
I have a Map<Integer, List<Float>> that represent a position with some scores, and I

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.