[Solved] Return specific object from an ArrayList
I assume you want to search in your AirbnbListing list. You can use Java Stream. Use the filter method for that: List<AirbnbListing> matchingListings = listings.stream() .filter(l -> “Surrey”.equals(l.getCity())) .collect(Collectors.toList()); If you want a list of all cities, you can use the map method: List<String> matchingListings = listings.stream() .map(l -> l.getCity()) .collect(Collectors.toList()); Additionally here is an … Read more