-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
  • 37,586
  • 78
  • 186
  • 264

2 Answers2

5

to iterate is human, to recurse divine

necromancer
  • 23,916
  • 22
  • 68
  • 115
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
  • 922
  • 11
  • 24