1

I have a Java class that uses Spark. I need to filter out the header from JavaRDD. This is how I want to do this.

String first = data.first();
JavaRDD<String> filteredData = data.filter((String s) -> {return !s.contains(first);});

However, this code data.filter((String s) -> {return !s.contains(first);}) cannot be compiled. IntelliJ IDE says "Lambda expressions are not supported at this language level".

Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217

1 Answers1

4

You can use lambdas on Java 7, but it is a bit involved — you have to use something like Retrolambda.

Also you can do the same thing without lambdas. Lambdas can be easily represented via annonymous classes, however it is a lot more verbose.

final String first = data.first();
JavaRDD<String> filteredData = data.filter(new Function<String, Boolean>() {
  @Override public Boolean call(String s) {
    return !s.contains(first);
  }
});
pepyakin
  • 2,217
  • 19
  • 31