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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:03:45+00:00 2026-06-11T11:03:45+00:00

I have a set of values stored in Map/HashMap. Then I did a triple

  • 0

I have a set of values stored in Map/HashMap. Then I did a triple for loop to compare the values. The values are compared this way: First get the values for 0-1 then compare it to a set of values that starts with 1-x [1-2, 1-3,…1-n]. IF and ONLY IF the value of (e.g 0-1) is BIGGER THAN all the other values in the 1-x set value (e.g: 1-2, 1-3,…1-n), the IF-ELSE statement will trigger an event.

An example of the data is given in the code snippet below:

import java.util.HashMap;
import java.util.Map;

public class CompareSequence{

    public static void main(String[] args) 
    {
        Map<String, Integer> myMap = new HashMap<String, Integer>();
        myMap.put("0-1", 33);
        myMap.put("0-2", 29);
        myMap.put("0-3", 14);
        myMap.put("0-4", 8);
        myMap.put("1-2", 37);
        myMap.put("1-3", 45);
        myMap.put("1-4", 17);
        myMap.put("2-3", 1);
        myMap.put("2-4", 16);
        myMap.put("3-4", 18);

        for(int i = 0; i < 5; i++)
        {
            for(int j = i+1; j < 5; j++)
            {
                String testLine = i+"-"+j; 
                int itemA = myMap.get(testLine);

                for(int k = j+1; k < 5; k++)
                {
                    String newLine = j+"-"+k;
                    int itemB = myMap.get(newLine);

                    if(itemA > itemB)
                    {
                        //IF and ONLY all values of item A that is passed through is bigger than item B
                        //THEN trigger an event to group item B with A
                        System.out.println("Item A : " + itemA + " is bigger than item " 
                        +  newLine + " (" +itemB + ")"); // Printing out results to check the loop
                    }
                    else
                    {
                        System.out.println("Comparison failed: Item " + itemA + " is smaller than " + newLine + " (" + itemB + ")");
                    }
                }
            }       
        }                   
    }
}

Current Result:
Get main value for comparison: myMap.get(0-1) = 33

Get all values related to Key 1-x (set value) ..
myMap.get(1-2) = 37 // This value is bigger than myMap.get(0-1) = 33
myMap.get(1-3) = 45 // This value is bigger than myMap.get(0-1) = 33
myMap.get(1-4) = 17 // This value is smaller than myMap.get(0-1) = 33

In that example given, the IF-ELSE statement should not let it pass, ONLY if all are smaller than 33, should an event be triggered. Is there something different I should do to the IF-ELSE statement or is there a problem with my loop?

Desired Result: 

If((myMap.get(0-1) > myMap.get(1-2)) && (myMap.get(0-1) > myMap.get(1-3)) && (myMap.get(0-1) > myMap.get(1-4))...(myMap.get(0-1) > myMap.get(1-n))
{
    //Trigger event to group all set values 1-x to value key 0-1
    //Then delete all set valued related to 1-x from list
}

Any advice or help would be greatly appreciated. Thank you!

  • 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-11T11:03:46+00:00Added an answer on June 11, 2026 at 11:03 am

    You could try something like this:

    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            String testLine = i + "-" + j;
            int itemA = myMap.get(testLine);
    
            boolean greaterThanAll = true;
    
            for (int k = j + 1; k < 5; k++) {
                String newLine = j + "-" + k;
                int itemB = myMap.get(newLine);
    
                if (itemA <= itemB) {
                    System.out.println("Comparison failed: Item " + itemA + " is smaller than " + newLine + " (" + itemB + ")");
                    greaterThanAll = false;
                    break;
                } else {
                    System.out.println("Item A : " + itemA + " is bigger than item "
                            + newLine + " (" + itemB + ")"); // Printing out results to check the loop
                }
            }
            if (greaterThanAll) {
                System.out.println(testLine + "=" + itemA + " is greater than all");
                //IF and ONLY all values of item A that is passed through is bigger than item B
                //THEN trigger an event to group item B with A
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String,
I have a set of data stored in a HashMap. The elements in the
Suppose I have a set of values, stored in a std::set: {1, 2, 6,
I have a stored procedure that says update table1 set value1 = 1 where
I have a set of values that I'm pushing into an array in the
public void test(Object obj){ //Here i have to set the values of the obj
I have a set of experimental values. For instance, I have a value of
I have a large set of values V, some of which are likely to
I have set up an update query which will update values entered into text
I have a set of three double values as part of an anonymous expression

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.