import java.util.*;
class Main
{
public static void main(String[] args) {
ArrayList<String> list1 = new ArrayList<String>();
list1.add("Hi");
list1.add("How");
list1.add("Are");
list1.add("You");
list1.add("Doing?");
printl("List: "+list1);
list1 = doubleList(list1);
printl("Double List: "+list1);
list1 = removeOddLength(list1);
printl("Odds removed: "+list1);
printl();
ArrayList<Integer> intList0 = newIntList(1,4,8,9,11,15,17,28,41,59);
ArrayList<Integer> intList1 = newIntList(4,7,11,17,19,20,23,28,37,59,81);
printl("Int List: "+intList0);
printl("Int List: "+intList1);
printl("Intersection: "+intersect(intList0, intList1));
}
public static ArrayList<String> doubleList (ArrayList<String> original)
{
ArrayList<String> list = new ArrayList(original);
for(int i = 0; i < list.size(); i+=2)
{
list.add(i,list.get(i));
}
return list;
}
public static ArrayList<String> removeOddLength (ArrayList<String> original)
{
ArrayList<String> list = new ArrayList(original);
for(int i = list.size()-1; i >= 0; i--)
{
if (list.get(i).length() % 2 != 0)
list.remove(i);
}
return list;
}
public static ArrayList<Integer> intersect (ArrayList<Integer> list0, ArrayList<Integer> list1)
{
ArrayList<Integer> n = new ArrayList<Integer>();
for(int i : list0)
{
for (int j : list1)
{
if (i==j)
n.add(i);
}
}
return n;
}
//just to make it easier to write out s.o.p(...)
public static void print(Object ... args)
{
//String val = args[0].toString();
for(int i = 0; i < args.length; i++)
System.out.print(args[i].toString());
}
public static void printl(Object ... args)
{
//String val = args[0].toString();
print(args);
System.out.println();
}
public static ArrayList<Integer> newIntList (int ... args)
{
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i = 0; i < args.length; i++)
list.add(args[i]);
return list;
}
}