Q:

Porting from Python to Java: looking for a fast implementation of an array search operation

I am porting some Python code into Java and need to find an efficient implementation of the following Python operation:
sum([x in lstLong for x in lstShort])

where lstLong and lstShort are string lists. So here I am counting how many elements from lstShort appear in lstLong. In the Java implementation, both of these are String[]. What's the fastest way of counting this sum?
A more general question is whether there are any generic guidelines for writing "fast equivalents" in Java of Python list comprehension operations like the one above. I am mostly interested in arrays/lists of Strings, in case it makes the answer easier.

A:

If you convert both to ArrayList<String>, you can use
lstLong.retainAll(lstShort).size();

You can do the conversion with
new ArrayList<String>(Arrays.asList(var));

