java - First try at lambda -


I tried to make my first lambda example but I can not find simple code to do this work.

  Import java.util.ArrayList; Import java.util.function.Predicate; Public square lambda {public static zero main (string [] args) {last string [] name = {"Wim", "Kian", "Dirk", "Emmanuel", "Frank", "Mica", "Anna" "Damien", "Alberto"}; Last string [] filteredNames = getNamesWithCriteria (names, (strings) -> gt; s.startsWith ("A")); } Private string [] getNamesWithCriteria (last string [] name, Predicate & lt; string & gt; predicate] {Final ArrayList & lt; String & gt; Filtered Name = New Arraylight & lt; & Gt; (); {String (name: name) for {if (predicate.test (name)} {filteredNames.add (name); }} Return (string []) filteredNames.toArray (); }}   

These errors I get:

  Lambda.java:8: error: ')' expected final string [] filteredNames = getNamesWithCriteria ( Name, (strings) -> gt; s.startsWith ("A")); ^ Lambda.java:8: Error: Invalid beginning expression of the last string [] filtered name = filth with names (names, (strings) -> gt; s.startsWith ("A")); ^ Lambda.java: 8: error: ';' Expected final string [] filteredNames = getNamesWithCriteria (names, (strings) -> gt; s.startsWith ("A"));    

You are not using Java 8 in your project. It is compiled exactly in Java 8. However in this line you have a bug:

  back (string []) filteredNames.toArray ();   

If you want to return an array, change the statement back to it.

  Return filtered name. Octroi (new string [filtered.Names.size ()]);    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -