Verwendung von Java 8 Lambda Expressions
Ich benutze Java JDK Version jdk1.8.0_77 für beide Android Studio.
Ich habe auch jackOptions in Großbuchstaben
Ich habe einfache Liste erstellen und Methode Filter hinzufügen und sortiert, aber nach langer Zeit habe ich Suche, aber keine Lösung.
Android java.lang.NoSuchMethodError: java.util.List.stream Verwendung java 8 Lambda Expressions
Gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
jackOptions {
enabled true
}
applicationId "com.mobisharnam.meme"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
MainActivity
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> list =
Arrays.asList("a1", "a2", "a3", "b1", "c2", "c1");
list.stream().
filter(s -> s.startsWith("c")).
sorted().forEach(s -> Log.d("TEST", s));
}
}
[überprüfen Sie das] (http://stackoverflow.com/questions/122105/what-is-the-best-way-to-filter-a-java-collection) überprüfen Sie diese Antwort ... –