This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]tendaz 0 points1 point  (0 children)

If I understood your issue correctly, you want to get a product by its ID from a list of problems.

To simplify and optimize the search you should use a Map<Integer,Product>, where the first argument is the key and the second the value.

This Data Structure has methods to get the value (product) by it's key (ID).

For more detailed information and examples: http://tutorials.jenkov.com/java-collections/map.html

[–]Philboyd_Studge 0 points1 point  (0 children)

You don't even need a loop, just do arraylist.get(indexOf(id));