Here is a full code of what you ask.
package main;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestMainClass
{
public static void main(final String[] args)
{
final Map<Integer, String> map = createDummyMap();
final List<Value> list = createList();
final List<Value> matchedValues = new ArrayList<TestMainClass.Value>();
for (final Value value : list)
{
for (final Integer id : map.keySet())
{
if (id.equals(value.getId()))
{
matchedValues.add(value);
}
}
}
System.out.println(matchedValues.size());
}
private static List<Value> createList()
{
final Value value1 = new Value(1001, "some");
final Value value2 = new Value(1002, "some");
final Value value3 = new Value(1003, "some");
final Value value4 = new Value(1004, "some");
final Value value5 = new Value(1005, "some");
return new ArrayList<TestMainClass.Value>(Arrays.asList(value1, value2, value3, value4, value5));
}
private static Map<Integer, String> createDummyMap()
{
final Map<Integer, String> valueMap = new HashMap<Integer, String>();
valueMap.put(1001, "Test1");
valueMap.put(1002, "Test2");
valueMap.put(1003, "Test3");
return valueMap;
}
public final static class Value
{
private int id;
private String value;
Value(final int id, final String value)
{
this.id = id;
this.value = value;
}
public int getId()
{
return id;
}
public void setId(final int id)
{
this.id = id;
}
public String getValue()
{
return value;
}
public void setValue(final String value)
{
this.value = value;
}
}
}