https://github.com/andyatkinson/java-stuff
Junk drawer of Java code/scripts/tests for learning
https://github.com/andyatkinson/java-stuff
Last synced: 3 months ago
JSON representation
Junk drawer of Java code/scripts/tests for learning
- Host: GitHub
- URL: https://github.com/andyatkinson/java-stuff
- Owner: andyatkinson
- Created: 2018-07-27T15:16:07.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-31T21:41:31.000Z (about 4 years ago)
- Last Synced: 2024-10-19T02:14:45.550Z (7 months ago)
- Language: Java
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Java Playground
### Build
This project was built with Java 8 using IntelliJ IDEA.
This is a Maven project.
### Command line
```java
mvn exec:java -Dexec.mainClass="Playground"
```Execute in parallel, specifying number of threads.
```java
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
`stream()`
> A sequence of elements supporting sequential and parallel aggregate operations.
* [Streams javadoc](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html)
* [Streams tutorial](https://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/)`filter`, `map`, `sorted` are intermediate operations, where `forEach` is terminal.
Streams may be iterated in parallel.
`Collectors.groupingBy`
`Collectors.toMap`### Lists
```java
final ArrayList list = new ArrayList(Arrays.asList("Ryan", "Julie", "Bob"));final List a = new ArrayList(Arrays.asList(1,2,3));
ImmutableList.of(1, 2, 3);
```