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 String
s, in case it makes the answer easier.