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
- [Streams & Collections](#streams)
- [Optional](#optional)
- [Records & Data Classes](#records)
- [Switch Expressions](#switch)
- [Concurrency](#concurrency)
- [Error Handling](#errors)
- [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
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
