Writing Java 7 functions in Lambda form:

Java 7 :

Example1:
return jdbcTemplate.query(sqlQueryToFetchList, new RowMapper() {
    public String mapRow(ResultSet rs, int rowNum) throws    SQLException {
        return rs.getString(1);
    }
});

Example2:
Collections.sort(list, new Comparator>() {
     public int compare(Entry o1, Entry o2) {
         return (o2.getValue()).compareTo(o1.getValue());
     }
 });

Java 8:

Example1:
return jdbcTemplate.query( sqlQuery , (ResultSet rs, int rownum) -> rs.getString(1));

Example2:
Collections.sort(list, (o1, o2) -> o2.getValue().compareTo(o1.getValue()));

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.