Java Iterator contains(Iterator iterator, String value)

Here you can find the source of contains(Iterator iterator, String value)

Description

Determines if a String value is included in a Iterated list.

License

Apache License

Parameter

Parameter Description
iterator a parameter
value a parameter

Declaration

public static boolean contains(Iterator<String> iterator, String value) 

Method Source Code

//package com.java2s;
/*//from w  w  w  . j  av  a 2  s  . co m
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */

import java.util.Iterator;

public class Main {
    /**
     * Determines if a String value is included in a Iterated list.
     * The iteration is only run as far as necessary to determine
     * if the value is included in the underlying list.
     *
     * @param iterator
     * @param value
     * @return
     */
    public static boolean contains(Iterator<String> iterator, String value) {
        if (iterator == null || value == null) {
            return false;
        }
        while (iterator.hasNext()) {
            if (value.equals(iterator.next())) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. concatIterators(final Iterator... iterators)
  2. concatLines(Iterator lineIterator)
  3. contains(final Iterator iter, final E item)
  4. contains(Iterator it, T o)
  5. contains(Iterator iterator, Object element)
  6. convertToArray(Iterator iter)
  7. convertToList(Iterator iter)
  8. copy(Iterator iterator)
  9. copyIterator(Iterable iterable)