2

Using java 8 Lambda Expressions
I am using Java JDK version jdk1.8.0_77 for both Android Studio.
I have also add jackOptions in gradle
I have create simple list and add method filter and sorted but after long time i have search but not any solution.

Gradle file

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));

}
}
user1516873
  • 5,060
  • 2
  • 37
  • 56
Joy
  • 289
  • 1
  • 15
  • [check this](http://stackoverflow.com/questions/122105/what-is-the-best-way-to-filter-a-java-collection) check out this answer... – Maulik Santoki Mar 29 '17 at 09:55

1 Answers1

1

The problem is that you are NOT chaining the stream methods properly, you can look below code:

list.stream().
            filter(s -> s.startsWith("c")).
            sorted().forEach(s -> Log.d("TEST", s));
Vasu
  • 21,832
  • 11
  • 51
  • 67
  • You can look here, similar issue:http://stackoverflow.com/questions/36652633/collection-nosuchmethoderror-when-caling-stream-method – Vasu Mar 29 '17 at 08:30