Java Formatter
Format and validate Java code online for free with the Prettier Java plugin.
Local browser processing
No sign-up required
Supports modern Java syntax
LanguageFor Java code
Javainput.java
Indent
Line width
⌘⏎Quick format
InputEditable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
OutputJava valid29 lines · 695 B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.List;
import java.util.ArrayList;
import java.util.Optional;
public class UserService {
private final UserRepository repo;
private final int maxResults;
public UserService(UserRepository repo, int maxResults) {
this.repo = repo;
this.maxResults = maxResults;
}
public List<User> findActive() {
var results = new ArrayList<User>();
for (var user : repo.findAll()) {
if (user.isActive()) {
results.add(user);
}
}
return results.subList(0, Math.min(results.size(), maxResults));
}
public Optional<User> findById(long id) {
return repo.findAll().stream()
.filter(u -> u.getId() == id)
.findFirst();
}
}
UTF-8 · Indent: 4 spaces · Line width: 80Local processing · Ready
How It WorksJava
Overview
This Java formatter cleans up code with inconsistent indentation or mixed styles into a unified style, powered by the Prettier Java plugin's real syntax parser. Generics, lambdas, records, sealed classes, and other modern syntax are all correctly recognized. Everything runs locally in your browser; your data never leaves your device.
Use Cases
Unify a team's Java code styleClean up code minified onto a single lineCheck whether class and method syntax is correctFormat code pasted from docs or generated by AI
Steps
123
Paste or uploadAdjust format optionsGet the result