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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:05:20+00:00 2026-06-06T14:05:20+00:00

I am filtering the all list which ahve same lat,long in one list and

  • 0

I am filtering the all list which ahve same lat,long in one list and put into an same list and put that list into map My code is as:-

private Collection<List<Applicationdataset>> groupTheList(ArrayList<Applicationdataset> arrayList)
  {
    Map<Key, List<Applicationdataset>> map = new HashMap<Key, List<Applicationdataset>>();
    for(Applicationdataset appSet: arrayList)
       {
        Key key = new Key(appSet.getLatitude(), appSet.getLongitude());
        List<Applicationdataset> list = map.get(key);
        if(list == null){
            list = new ArrayList<Applicationdataset>();

        }
        list.add(appSet);
             map.put(key, list);
    }
    return map.values();
}


public class Key {
    String _lat;
    String _lon;

    Key(String lat, String lon) {
        _lat = lat;
        _lon = lon;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Key key = (Key) o;

        if (!_lat.equals(key._lat)) return false;
        if (!_lon.equals(key._lon)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = _lat.hashCode();
        result = 31 * result + _lon.hashCode();
        return result;
    }
}

But When I am debuging my code according to xml which come from web-service there is 2 list which have same lat long and they are saving in same list in amp at time of debuging but when I go next step of debug the element of map which have 2 item list decrease and showing size 1 I am unable to rectify this issue.

  • 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-06T14:05:22+00:00Added an answer on June 6, 2026 at 2:05 pm

    Your code looks OK: You’ve overridden equals() and hashCode() consistently.

    Check for whitespace in the lat/lng values as the cause of your problems, perhaps trim() in the constructor:

    Key(String lat, String lon) {
        _lat = lat.trim();
        _lon = lon.trim();
    }
    

    Also, you can simplify your code to this:

    @Override
    public boolean equals(Object o) {
        return o instanceof Key
            && _lat.equals(((Key)o)._lat))
            && _lon.equals(((Key)o)._lon));
    }
    
    @Override
    public int hashCode() {
        // String.hashCode() is sufficiently good for this addition to be acceptable
        return _lat.hashCode() + _lon.hashCode();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: private Dictionary<int, Entity> m_allEntities; private Dictionary<Entity, List<IComponent>> m_entityComponents; public
I have a list of Person s each which have multiple fields that I
I'm downloading a long list of my email subject lines , with the intent
I have a list of items that are in this format: 05/01 – Some
I need to find all the records that have no associated records in any
All right, I've seen some posts asking almost the same thing but the points
I have an Order class that has a list of OrderTransactions and I mapped
First of all, here is a JSFiddle which has the problem I'm getting. http://jsfiddle.net/UG66K/9/
I have a list of items, which belong to a group. So I could
I'm using the ' Filtering Blocks ' tutorial on the CSS-Tricks website which allows

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.