Complete AI TrainingYourJobSkills for your job

Skills / super-code

java

Language-specific super-code guidelines for java.

Java: Idiomatic Efficiency Reference

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for java.

Table of Contents

  1. [Streams & Collections](#streams)
  2. [Optional](#optional)
  3. [Records & Data Classes](#records)
  4. [Switch Expressions](#switch)
  5. [Concurrency](#concurrency)
  6. [Error Handling](#errors)
  7. [Anti-patterns specific to Java](#antipatterns)

1. Streams & Collections {#streams}

// ❌ Imperative accumulation
List<String> result = new ArrayList<>();
for (Item item : items) {
    if (item.isActive()) result.add(item.getName().toUpperCase());
}

// ✅
List<String> result = items.stream()
    .filter(Item::isActive)
    .map(item -> item.getName().toUpperCase())
    .toList(); // Java 16+; use .collect(Collectors.toList()) before
// ❌ Manual grouping
Map<String, List<Item>> grouped = new HashMap<>();
for (Item item : items) {
    grouped.computeIfAbsent(item.getCategory(), k -> new ArrayList<>()).add(item);
}

// ✅
Map<String, List<Item>> grouped = items.stream()
    .collect(Collectors.groupingBy(Item::getCategory));
// ❌ Manual sum
int total = 0;
for (Order o : orders) total += o.getAmount();

// ✅
int total = orders.stream().mapToInt(Order::getAmount).sum();

**Prefer method references (Item::isActive) over equivalent lambdas (`item -> item.isActive()

Subscribers only

The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.

Details

Sourcecommunity
License
Risk labelsafe ("critical" means the skill may run commands or touch files — read before use)
FilesSKILL.md
Added2026-06-16

Related skills

bash

Language-specific super-code guidelines for bash.

c

Language-specific super-code guidelines for c.

cpp

Language-specific super-code guidelines for cpp.

csharp

Language-specific super-code guidelines for csharp.

dart

Language-specific super-code guidelines for dart.

elixir

Language-specific super-code guidelines for elixir.