Results 1 to 2 of 2
  1. #1
    mayhewj7 is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default iterator method help..

    I currently have a linked set implementation that has a method called contains that returns true if a set contains a certain element and false if it does not.

    public boolean contains(Object target){
    boolean found = false;
    LinearNode<Object> current = contents;

    for(int i = 0; i < count && !found; i ++){
    found = true;
    current = current.getNext();
    return found;

    I need to create a new method called eitherContains that returns true if this set or the one passed as a parameter contains the target element.

    The catch is I can't use other.contains(target), I have to use the iterator method for the other set.

    this is where im confused, not sure how to use the iterator method here.Hopefully someone can help.....

    public boolean eitherContains(Object target, Set other){


  2. #2
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Virginia Beach, Virginia
    Rep Power


    Well if the other object is of type Set, then you should be able to do something liked
    Java Code:
    public boolean eitherContains(Object target, Set s) {
            // your other code
            Iterator it = s.iterator();
            while(it.hasNext()) {
                    return true;
            return false;
    Look at the java api documentation for the Iterator and Set class.

    I assume that you can probably use the iterator for both Sets

Similar Threads

  1. curious about iterator
    By jacline in forum New To Java
    Replies: 1
    Last Post: 03-16-2009, 04:29 AM
  2. [SOLVED] Writing an Iterator method in a custom list
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 02-12-2009, 05:22 AM
  3. iterator
    By venkatallu in forum Advanced Java
    Replies: 3
    Last Post: 09-23-2008, 01:32 PM
  4. iterator issues
    By orchid in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 01:43 PM
  5. Iterator
    By eva in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 02:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts