I\'ve read this post here. But still I cannot run code containing Java 8 Stream API features like the following on minSdkVersion < 24.
List new
Create a İnterface.
public interface Pre {
R get(T item);
}
Create a Filter Method.
public static List Filter(List list, Pre pre) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
return list.stream().filter(p -> pre.get(p)).collect(Collectors.toList());
}
else
{
List col = new ArrayList();
for (int i = 0 ; i < list.size() ; i++)
if (pre.get(list.get(i)))
col.add(list.get(i));
return col;
}
}
Using Code
public static class model {
public String Name;
}
List models = new ArrayList<>();
...
List filtermodels = Filter(models,p-> p.Name.equals("filter"));