All pastes #334479 Raw Edit

Something

public text v1 · immutable
#334479 ·published 2007-01-31 17:18 UTC
rendered paste body
import java.util.*;

public class Leikkaus {
	
	public static void main(String[] args) {
		ArrayList<Object> t1 = new ArrayList<Object>();
		t1.add(1);
		t1.add(2);
		t1.add(5);
		t1.add(6);
		t1.add(7);
		ArrayList<Object> t2 = new ArrayList<Object>();
		t2.add(2);
		t2.add(6);
		t2.add(9);
		System.out.println(t1 + "\n" + t2);
		System.out.println(leikkaus(t1, t2));
	}
	
	public static ArrayList<Object> leikkaus(ArrayList<Object> a, ArrayList<Object> b) {
		ArrayList<Object> c = new ArrayList<Object>();
		for (int i = 1; i < a.size(); ++i) {
			if (b.contains(a.get(i)))
				c.add(a.get(i));
		}
		return c;
	}
}