| name | java-algorithm-patterns |
| description | 5 algorithm patterns with full Java implementations for common coding problems |
| version | 1.0.0 |
| category | toolchain |
| author | Claude MPM Team |
| license | MIT |
| progressive_disclosure | {"entry_point":{"summary":"Java algorithm patterns: Stream API, Binary Search, HashMap, Graph (JGraphT), Concurrent Collections","when_to_use":"When implementing algorithms, data structures, or solving coding problems in Java","quick_start":"Each pattern includes full implementation, complexity analysis, and key principles"}} |
| context_limit | 700 |
| tags | ["java","algorithms","stream-api","binary-search","hashmap","jgrapht","concurrent-collections","data-structures","complexity"] |
| requires_tools | [] |
Java Algorithm Patterns
Algorithm Patterns
1. Stream API Pattern (Functional Processing)
import java.util.*;
import java.util.stream.*;
public class StreamPatterns {
public static int lengthOfLongestSubstring(String s) {
if (s == null || s.isEmpty()) {
return 0;
}
Map<Character, Integer> charIndex = new HashMap<>();
int maxLength = 0;
int left = 0;
for (int right = 0; right < s.length(); right++) {
char c = s.charAt(right);
if (charIndex.containsKey(c) && charIndex.get(c) >= left) {
left = charIndex.get(c) + 1;
}
charIndex.put(c, right);
maxLength = Math.max(maxLength, right - left + );
}
maxLength;
}
Map<String, Long> {
items.stream()
.collect(Collectors.groupingBy(
item -> item,
Collectors.counting()
));
}
}