Skip to content

andyatkinson/java-stuff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Playground

Build

This project was built with Java 8 using IntelliJ IDEA.

This is a Maven project.

Command line

mvn exec:java -Dexec.mainClass="Playground"

Execute in parallel, specifying number of threads.

mvn exec:java -Djava.util.concurrent.ForkJoinPool.common.parallelism=4 -Dexec.mainClass="Parallel"

Tips

These will require Java 8+

javarepl

Objects.requireNonNull()

  • Use this instead of doing manual null checks.

Playground.frequency(Collection c, Object o)

  • Count number of occurrences of object in collection

UUID.randomUUID()

  • Generate a random UUID for tests

Optional.ifPresent()

  • Use a functional programming style and execute a block when object is present

Immutables

https://dzone.com/articles/immutability-with-builder-design-pattern

stream()

A sequence of elements supporting sequential and parallel aggregate operations.

filter, map, sorted are intermediate operations, where forEach is terminal.

Streams may be iterated in parallel.

Collectors.groupingBy Collectors.toMap

Lists

final ArrayList<String> list = new ArrayList(Arrays.asList("Ryan", "Julie", "Bob"));

final List a = new ArrayList(Arrays.asList(1,2,3));

ImmutableList.of(1, 2, 3);

About

Junk drawer of Java code/scripts/tests for learning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages