Skip to content
Wei Li
Go back

Interactive Java Examples with Vue

Edit page

Two companions to the Java guides on this site, built as Vue components. Both are rendered to HTML at build time and come alive in the browser when they scroll into view (client:visible). See Using Vue Components in Posts for how that works.

Stream pipeline playground

Build a pipeline out of intermediate operations, then pick a terminal operation. Each step shows how many elements went in and out, and the Java code below updates as you go. Try moving limit above filter, or squaring large numbers: the arithmetic overflows exactly like Java’s 32-bit int.

Intermediate operations

  1. .filter(n -> n % 2 != 0)
    10 → 73115953
  2. .distinct()
    7 → 43159
  3. .sorted(Comparator.reverseOrder())
    4 → 49531
  4. .limit(3)
    4 → 3953
Terminal operation
Result (List<Integer>)
[9, 5, 3]
Java
List<Integer> result = Stream.of(3, 1, 4, 1, 5, 9, 2, 6, 5, 3)
    .filter(n -> n % 2 != 0)
    .distinct()
    .sorted(Comparator.reverseOrder())
    .limit(3)
    .toList();

More on the operations themselves in the Java Stream API guide.

Java collections explorer

The common java.util collections side by side. Filter by interface or property, sort by the cost of an operation, and click a class name for notes on when to use it.

12 of 12
Order
no nulls
Queueinsertion— O(1*) O(n) O(n)
Listinsertion O(1) O(1*) O(n) O(n)
thread-safe·no nulls
Mapnone O(1) O(1) O(1) O(1)
thread-safe
Listinsertion O(1) O(n) O(n) O(n)
Mapnone O(1) O(1) O(1) O(1)
Setnone— O(1) O(1) O(1)
Mapinsertion O(1) O(1) O(1) O(1)
Setinsertion— O(1) O(1) O(1)
List, Queueinsertion O(n) O(1) O(n) O(n)
no nulls
Queuepriority— O(log n) O(n) O(n)
no nulls
Mapsorted O(log n) O(log n) O(log n) O(log n)
no nulls
Setsorted— O(log n) O(log n) O(log n)

Average-case costs. O(1*) is amortized: usually constant, occasionally O(n) when the backing array grows. Click a class name for notes, or a column header to sort.

How they’re built

Both components are single-file Vue 3 components using <script setup> and TypeScript, and they rely on a handful of Vue features:

Their source is in src/components/StreamPipeline.vue and src/components/CollectionsExplorer.vue.


Edit page
Share this post:

Previous Post
A Java Regex Tester
Next Post
Using Vue Components in Posts