Ahmed Abd Elfattah
Ahmed Abd Elfattah

Reputation: 59

Rewrite java 8 method with Lightweight-Stream-API for using for api 21

I don't know all capabilities of Stream API.

I have an AutoCompleteTextView with custom adaptor,I made a method that know if entered data in AutoCompleteTextView is from suggested data or not , Call requires API level 24 (current min is 21) Error

Now I want rewrite it using Lightweight-Stream-API for using under api 24

method in java8

 private boolean isFromSuggestedData(List<StoreCategory> list, final String nameEnglish){
   return list.stream().anyMatch(item -> nameEnglish.equals(item.getNameEnglish()));
}

Upvotes: 3

Views: 178

Answers (1)

You can use kotlin "any" function

private fun isFormSuggestedData(list: List<StoreCategory>, nameEnglish: String): Boolean = list.any { nameEnglish == it.nameEnglish }

Upvotes: 1

Related Questions