Cheat Sheets - Java 8
Cheat Sheets - Java 8
(http://www.ohmdb.com)
Lambda syntax
Run a Runnable
The PI function
// equivalent to:
Arrays.sort(words, (String s1, String s2) -> s1.length() - s2.length());
// Class::staticMethod syntax
Arrays.sort(items, Util::compareItems);
// equivalent to:
Arrays.sort(items, (a, b) -> Util.compareItems(a, b));
// instance::instanceMethod syntax
items.forEach(System.out::print);
// equivalent to:
items.forEach((x) -> System.out.print(x));
// Class::instanceMethod syntax
items.forEach(Item::publish);
// equivalent to:
items.forEach((x) -> { x.publish(); });
Constructor reference
interface Descriptive {
// prints "fantastic"
System.out.println(x.desc());
Get count, min, max, sum, and average statistics for items rating
Sponsors:
OhmDB db = Ohm.db("my.db");
Table<Item> items;
items = db.table(Item.class);
Item foo = new Item("foo");
long id = items.insert(foo);
(http://empty)
All articles:
Caching with ConcurrentHashMap and computeIfAbsent (caching-with-ConcurrentHashMap-in-java-
8.html)
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be
trademarks of their respective owners.