-1

I have an object class named Store which has an attribute "year":

public class Store{
     public int year;
     ...
}

Then, in another class I got a list of Store :

List<Store> stores = getAllStores();

I would like to get from the list the 1st occurrence of store whose year is 2002 without using for loop or while loop. Is it possible?

Mellon
  • 35,610
  • 77
  • 182
  • 262

2 Answers2

5

to iterate is human, to recurse divine

necromancer
  • 22,906
  • 22
  • 66
  • 114
0

I think you wanted something like ReturnTop where year is 2002, which there are 2 conditions underlying.

Is the objects sorted before added into the list? Is there any patterns that uniquely identify 2002 or have you consider hashmap? Have you considered a stack or a queue where 2002 is the first or the last added?

CalebC
  • 862
  • 10
  • 24