This looks like a situation suitable for Map<Long, Person> , which maps the social security number to the corresponding Person . You might want to remove the ssnNo field from Person to avoid any layoffs (since you will store these values โโas keys on your card).
In general, Map and List are very different structures, each of which is suitable for different circumstances. You would use the first one when you want to maintain a set of key-value pairs, which allows you to easily and quickly (i.e., in constant time) search for values โโbased on keys (this is what you want to do). You would use the latter when you just want to keep an ordered, linear set of elements.
source share