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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:20:37+00:00 2026-06-13T21:20:37+00:00

I would like to check if two bundles are equal, is there any way

  • 0

I would like to check if two bundles are equal, is there any way to do that instead of checking them key by key?

  • 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-13T21:20:39+00:00Added an answer on June 13, 2026 at 9:20 pm

    Here is one way to test if two Bundles are the same:

    • Check their sizes, don’t bother if they’re not equal
    • If both values are Bundle objects use recursion
    • Because a value for a key in one can be null, make sure that both values are null and that the key actually exists in two
    • Finally compare the matching keys’ values

    Code:

    public boolean equalBundles(Bundle one, Bundle two) {
        if(one.size() != two.size())
            return false;
    
        Set<String> setOne = new HashSet<>(one.keySet());
        setOne.addAll(two.keySet());
        Object valueOne;
        Object valueTwo;
    
        for(String key : setOne) {
            if (!one.containsKey(key) || !two.containsKey(key))
                return false;
    
            valueOne = one.get(key);
            valueTwo = two.get(key);
            if(valueOne instanceof Bundle && valueTwo instanceof Bundle && 
                    !equalBundles((Bundle) valueOne, (Bundle) valueTwo)) {
                return false;
            }
            else if(valueOne == null) {
                if(valueTwo != null)
                    return false;
            }
            else if(!valueOne.equals(valueTwo))
                return false;
        }
    
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to do two things within my Android app : Check if
I would like to check that I have workingDir = C:\Users\~\Temp\workspace_folder; for i=1:2 %
$('tr').find(need help here).parent().css('backgroundColor', '#fcc'); Would like to perform inequality check of two dates (both
I would like to check, is it possible to left join two tables using
I would like to check how to print a success message if there is
I would like check how iteration is between two dates with interval 30 minutes.
I'd like to check if two arrays are equal. I mean: same size, same
I have a two tables A and B I would like to union them
Given a list of urls, I would like to check that each url: Returns
I have two strings and I would like to check whether the first is

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.