Here you can find the source of contains(final Iterator extends E> iter, final E item)
Parameter | Description |
---|---|
E | the element type |
iter | the iterator |
item | the item |
public static <E> boolean contains(final Iterator<? extends E> iter, final E item)
//package com.java2s; /**// ww w .j a va 2 s .com * Licensed to the TomTom International B.V. under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. TomTom International B.V. * licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.Iterator; public class Main { /** * Checks if an element item is contained in the iterator sequence. * * The iterator cannot be re-used after calling this function!! * * @param <E> the element type * @param iter the iterator * @param item the item * @return true, if the element is in the iterator sequence */ public static <E> boolean contains(final Iterator<? extends E> iter, final E item) { if (iter == null || item == null) { throw new NullPointerException(); } while (iter.hasNext()) { if (item.equals(iter.next())) { return true; } } return false; } }