First, I would advise you to use generics . And secondly, for a2maybe Set. And thirdly, you may need to change from Stringto Integer(since they are all integers).
But for your example, this is the way to do this:
ArrayList<Integer> a3 = new ArrayList<Integer>();
for (String a : a1)
a3.add(a2.contains(a) ? 1 : 0);
Full example (with type HashSetand Integer):
public static void main(String... args) {
List<Integer> a1 = Arrays.asList(5, 10, 20, 50, 100, 500, 1000);
Set<Integer> a2 = new HashSet<Integer>(Arrays.asList(50, 500, 1000));
ArrayList<Integer> a3 = new ArrayList<Integer>();
for (Integer a : a1)
a3.add(a2.contains(a) ? 1 : 0);
System.out.println(a3);
}
Conclusion:
[0, 0, 0, 1, 0, 1, 1]
dacwe source
share