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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:17:03+00:00 2026-06-04T09:17:03+00:00

LinkedHashMap<String, Double> testMap = (LinkedHashMap<String, Double>) sortByValue(commands.get(commandWithMaxNegativeOffset).getDataUsageCriteria()); From above, testMap will contains something like

  • 0
LinkedHashMap<String, Double> testMap = (LinkedHashMap<String, Double>) sortByValue(commands.get(commandWithMaxNegativeOffset).getDataUsageCriteria());

From above, testMap will contains something like {New=30.0, Previous=70.0} in ascending order of value so what I want to do is something like below in the if/else loop, as currently I have hardcoded now just to make more sense but I want to use the testMap instead of hardcoding. I want to set key as value if condition gets matched by using key/value pair from map

double percent = r.nextDouble()*100;

if(percent > 1.0 && percent < 70.0(how can I use 70 from testMap instead of hardcoding)) {
//what to put below in place of Previous
    commands.get(commandWithMaxNegativeOffset).setDataCriteria(Use the Key of 70.0 i.e Previous);
} else if(percent > 71 && percent < 100){
    commands.get(commandWithMaxNegativeOffset).setDataCriteria(Use the Key of 30.0 i.e New);
}
  • 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-04T09:17:05+00:00Added an answer on June 4, 2026 at 9:17 am

    If I understand you correctly, the following may be what you’re looking for:

    final LinkedHashMap<String, Double> testMap = new LinkedHashMap<String, Double>();
    testMap.put("New", Double.valueOf(30.0));
    testMap.put("Previous", Double.valueOf(70.0));
    
    // The map contains two entries.
    Set<Map.Entry<String, Double>> entries = testMap.entrySet();
    Iterator<Map.Entry<String, Double>> it = entries.iterator();
    Map.Entry<String, Double> firstEntry = it.next();
    Map.Entry<String, Double> secondEntry = it.next();
    
    Random r = new Random();
    double percent = r.nextDouble() * 100;
    
    // percent is a number between 0.0 and 100.0
    if (percent < secondEntry.getValue().doubleValue()) // between 0.0 and 70.0 exclusive
    {
        commands.get(commandWithMaxNegativeOffset).setDataCriteria(secondEntry.getKey());
    }
    else // between 70.0 inclusive to 100.0 (100.0 - 70.0 = 30.0)
    {
        commands.get(commandWithMaxNegativeOffset).setDataCriteria(firstEntry.getKey());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have something like this: LinkedHashMap <String, ArrayList<String>> h keyOne has stringOne
I have LinkedHashMap returning from DB. From this map I need to get the
Lately I often have to read Java code like this: LinkedHashMap<String, Integer> totals =
I have LinkedHashMap<String,ArrayList<String>> h If I do this: System.out.println(h.get(key1)) ; it prints out this:
When I serialize my LinkedHashMap<String, String> using GSON, I get {b:a,a:1,c:2} and after deserializing
I have the first key/value pair in a LinkedHashMap, which I get from a
I have a LinkedHashMap (called info) that contains name/age (string/int) pairs. How can I
It would be nice to use for (String item: list) , but it will
Ive come across a nice problem recently, I have a Map LinkedHashMap<String, List<MyCustomObject>> I
I have a LinkedHashMap < String, String > map . List < String >

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.