3

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()));
}
MD Naseem Ashraf
  • 1,030
  • 2
  • 9
  • 22
  • 1
    The [test for `anyMatch`](https://github.com/aNNiMON/Lightweight-Stream-API/blob/master/stream/src/test/java/com/annimon/stream/streamtests/AnyMatchTest.java) looks like the `java.util.stream` one. Just try changing the `import`s ans stream creation as such. – Naman Jul 30 '19 at 02:02
  • thanks, @naman this made my day :) – Ahmed Abd Elfattah Feb 11 '22 at 21:39

1 Answers1

1

You can use kotlin "any" function

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