Use _ for variables you must declare but never use, clarifying intent.
var counts = new int[]{10, 20, 30};
int total = 0;
for (var _ : counts) {
total += 5; // we only care how many, not the value
}
System.out.println("total = " + total);
total = 15
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-26