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

  • Home
  • SEARCH
  • 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 6878599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:44:38+00:00 2026-05-27T04:44:38+00:00

I have a method which as an argument has an iterator to the collection.

  • 0

I have a method which as an argument has an iterator to the collection. Inside the method I want to copy the collection the iterator is “pointing to”.
However only the last collection entry is present in the collection copy, it is present N times, where N is the size of the original collection.

public void someMethod(Iterator<Node> values) {
  Vector<Node> centralNodeNeighbourhood = new Vector<Node>();
  while (values.hasNext()) {
    Node tmp = values.next();
    centralNodeNeighbourhood.add(tmp);
  }
  ...
  //store the centralNodeNeighbourhood on disk
}

Exemplar “original collection”:

1
2
3

Exemplar “centralNodeNeighbourhood collection”:

3
3
3

Can someone point me to my mistake? I can not change the method args, I only get the Iterator to the collection, can’t do anything about it.

UPDATE (Answer to some questions)

while (values.hasNext()) {
            Node tmp = values.next();
            System.out.print("Adding = "+tmp.toString());
            centralNodeNeighbourhood.add(tmp);
        }

Prints proper original collection elements.
I don’t know what type is the original collection, but the Iterator is from std java. The method is the

public class GatherNodeNeighboursInfoReducer extends MapReduceBase
        implements Reducer<IntWritable, Node, NullWritable, NodeNeighbourhood>{
    public void reduce(IntWritable key, Iterator<Node> values,
                   OutputCollector<NullWritable, NodeNeighbourhood> output, Reporter reporter) throws IOException {...}
}

method from OLD Hadoop api (Hadoop version 0.20.203.0)

SOLVED
I made a copy of tmp object at each iteration, and I add this copy to the centralNodeNeighbourhood collection. This solved my problem. Thx for all your (fast) help.

  • 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-27T04:44:39+00:00Added an answer on May 27, 2026 at 4:44 am

    Its appears that the Iterator is returning the same Node object each time. If so, you need to take a copy of the Node before adding it to the collection. (Otherwise you will be adding the same object each time and it will have the last values it was set to)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method which takes String argument. In some cases I want to
I have a class 'Collection', which has an add method. The add method should
I have a method which is given the parameter bool sortAscending. Now I want
I have a method which never returns a null object. I want to make
I have a UserBll class which has following method public string GetaspnetUserIdByUserName(string name )
I have a windows application which has 3 forms : Form1,2,3. I want to
I have a JAR with 4 classes, each one has Main method. I want
In an actionscript function (method) I have access to arguments.caller which returns a Function
I have a method which takes params object[] such as: void Foo(params object[] items)
I have a method which should be executed in an exclusive fashion. Basically, it's

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.