how to make generic arraylist in java

Java
import java.util.*;

public class Ex0b
{
  public static class MyPair<T>
  {
    T x, y;
    public MyPair(T o1, T o2)
    {
      x = o1;
      y = o2;
    }
    public T first() { return x; }
    public T second() { return y; }
  }
  
  public static void main(String[] args)
  {
    MyPair<String> p = new MyPair<String>("ying","yang");
    int n = p.first().length();
    System.out.println(n);
  }
}
Source

Also in Java: