/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.stream.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		List<B> list = Arrays.asList(
			new B(5, "toto"),new B(6, "toto"),new B(5, "tata"),new B(6, "tata"));
		B first5 = getLastBeFromInt(list, 5);
		System.out.println(first5);
		
		B first6 = getLastBeFromInt(list, 6);
		System.out.println(first6);
	}
	
	static B getLastBeFromInt(List<B> l, int i){
		return l.stream().filter(b->b.x==i).reduce((first, second) -> second).orElse(null);
	}
}


class B {
    int x;
    String y;
    public B(int x, String y){this.x=x;this.y=y;}
    public String toString(){return x+" "+y;}
 }