Google Guava Iterables Find Example

Alternative to java.util.iterator.

Other Google Guava examples:
Convert List to Map
Iterables Any Example
Better null checks using Optional Example
Convert Map to String

package com.idodevjobs;

import java.util.List;


public class GoogleGuavaIterablesFindExample {
	private String input;

	public static void main(String[] args) {

		List<GoogleGuavaIterablesFindExample> testList = Lists.newArrayList(
				new GoogleGuavaIterablesFindExample("input1"),
				new GoogleGuavaIterablesFindExample("input2"));
		System.out.println(getInstanceFromList("input1", testList));


	public static GoogleGuavaIterablesFindExample getInstanceFromList(
			final String input, List<GoogleGuavaIterablesFindExample> testList) {
		return Iterables.find(testList,
				new Predicate<GoogleGuavaIterablesFindExample>() {
					public boolean apply(
							GoogleGuavaIterablesFindExample googleGuavaIterablesFindExample) {
						return googleGuavaIterablesFindExample.getInput().equals(

    public GoogleGuavaIterablesFindExample(String input) {
        this.input = input;

    public String getInput() {
        return input;

    public void setInput(String input) {
        this.input = input;

	public String toString() {
		return "GoogleGuavaIterablesExample{" + "input='" + input + '\'' + '}';

This entry was posted in java and tagged , , , . Bookmark the permalink.

4 Responses to Google Guava Iterables Find Example

  1. Pingback: Convert List to Map using Google Guava in Java | iDoDevJobs

  2. Pingback: Google Guava Iterables Any Example | iDoDevJobs

  3. Pingback: Google Guava Optional Example | iDoDevJobs

  4. Pingback: Convert Map to String using Google Guava in Java | iDoDevJobs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s