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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:17:19+00:00 2026-05-31T11:17:19+00:00

Im having problems with removing items from an arraylist using an iterator. My aim

  • 0

Im having problems with removing items from an arraylist using an iterator. My aim is to retrieve points within a certain radius and cluster them into a set of groups. I am using the initial points as a reference. The code has an initial for loop that will run through each place, then for each place an inner for loop is created to check the radius between the reference place and the rest of places. If the radius between both reference place and other place is less than a threshold i set, it will be added to the arraylist grouped with other similar points. As they are added to groups they will be removed from the original arraylist.

However i am getting problems such as it either only performs the outer for loop once or i get an IllegalStateException.

Here is the code:

HashMap<Place, ArrayList<Place>> sets = new HashMap<Place, ArrayList<Place>>();

private void cluster(ArrayList<Place> places) {

    for (Iterator<Place> iterator = places.iterator(); iterator.hasNext();) {
        Place pl = iterator.next();
        ArrayList<Place> subset = new ArrayList<Place>(); // Group
        GeoPoint g = new GeoPoint((int) (pl.getGeometry().getLocation()
                .getLat() * 1e6), (int) (pl.getGeometry().getLocation()
                .getLng() * 1e6));
        Point point = new Point();
        mapView.getProjection().toPixels(g, point);
        sets.put(pl, subset);
        subset.add(pl);
        iterator.remove();

        for (Iterator<Place> iterator2 = places.iterator(); iterator2
                .hasNext();) {
            Place pl2 = iterator2.next();
            int threshold = 100;
            GeoPoint g2 = new GeoPoint((int) (pl2.getGeometry()
                    .getLocation().getLat() * 1e6), (int) (pl2
                    .getGeometry().getLocation().getLng() * 1e6));
            Point point2 = new Point();
            mapView.getProjection().toPixels(g2, point);
            int dx = Math.abs(point2.x - point.x);  
            int dy = Math.abs(point2.y - point.y);
            if (dx < threshold && dy < threshold) {
                subset.add(pl2);
                iterator2.remove();
            }
        }
    }
}

Sorry for the info overload, would really appreciate the help.

Thanks in advance peeps

Rehan

  • 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-05-31T11:17:20+00:00Added an answer on May 31, 2026 at 11:17 am

    You are stepping the outer iterator inside the inner loop. It looks like these lines might be in error:

    for (Iterator<Place> iterator2 = places.iterator(); iterator.hasNext();) {
        Place pl2 = iterator.next();
    

    Looks like maybe you copied and pasted without changing the terminating condition in the loop and the following line:

    for (Iterator<Place> iterator2 = places.iterator(); iterator2.hasNext();) {
           Place pl2 = iterator2.next();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems when it comes to removing a row from a table.
I'm having some problems removing clients from a channellist. This is the code i
I'm having problems removing a vector from a multidimensional vector I would like to
I am having a problem inserting and removing objects to/from the database using Linq
I'm new to iPhone development and am having problems removing a sub-view from the
Im having a problem with removing non-utf8 characters from string, which are not displaying
I am having a problem removing an option from my drop down list. It
I am having problems displaying images which have been queried from the database. The
I am having great problems running the application in the debugger from Visual Studio
I am having problems removing a temp table in SQL server. I have a

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.