Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static Object addInUpperCase(Object c, String s) { if (c.getClass().isAssignableFrom(List.class)) { ((List) c).add(s.toUpperCase()); } else if (c.getClass().isAssignableFrom(ArrayList.class)) { ((ArrayList) c).add(s.toUpperCase()); } return c; } }