Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;

import java.util.*;

public class Main {
    public static void filterIterables() {
        List<String> literals = Arrays.asList("1", "2", "3");
        Iterable<String> filtered = Iterables.filter(literals, new Predicate<String>() {

            @Override
            public boolean apply(String input) {
                return input.equals("1");
            }
        });

        System.out.println(Iterables.toString(filtered));

        Iterator<String> filtered2 = Iterators.filter(literals.iterator(), new Predicate<String>() {

            @Override
            public boolean apply(String input) {
                return input.equals("1");
            }
        });

        System.out.println(Iterators.toString(filtered2));
    }
}