{"id":4160,"date":"2016-05-18T00:28:01","date_gmt":"2016-05-18T00:28:01","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4160"},"modified":"2016-05-18T00:28:01","modified_gmt":"2016-05-18T00:28:01","slug":"java-8-lambda-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/java-8-lambda-example\/","title":{"rendered":"Java 8 Lambda example"},"content":{"rendered":"<p>Java Lambdas work about the same as other languages, except they use -> rather than =>.<\/p>\n<p>For instance, you can use these to filter a list with the streams API:<\/p>\n<pre lang=\"java\">\nList<String> data = new ArrayList<String>();\n\ndata.add(\"test1\");\ndata.add(\"test2\");\ndata.add(\"test3\");\ndata.add(\"test4\");\ndata.add(\"test5\");\n\nOptional<String> result =\n  data.stream().filter(\n    (x) -> x.equals(\"test3\")\n  ).findFirst();\n\nif (result.isPresent()) {\n    System.out.println(result.get());\n}\n<\/pre>\n<p>This is one of the few examples of Java code where it can successfully infer the type of the arguments selected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Java 8 lambda example<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[300,306],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4160"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4160"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4160\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}