I have list (array list)that can contain many instances (between 500-3000 instances ).
during the program some function need to access to this list (many times)and search for specific instance or more ,to get the instance\s they need loop on the list and provide parentName and name (which is string) and are not uniqe key .
my question is since the list need to be accessed many time there is a way to define/design it better that the access to the list can be more efficient?
Please keep in mind that the functions that need to get instance/s from the list
cannot provide full key the can provide only name and parentName which can have more that one instance.
List<Obj> myList = new ArrayList<Obj>();
class obj
{
parentName
Name
type
curr
....
Use a
Map<MyEntry, List<Obj>>whereMyEntryis a class enclosing parent name and name as such:You can, for instance, have a method in your
Objwhich returns the matchingMyEntryobject. Also, if you use Guava, have a look atMultiMap.You will notice that the hash code is precomputed: this can be done since the
MyEntryclass is immutable. This allows for very fast usage as keys for aMap.(edit: added
.toString())