← All Exercises
Local Variable Type Inference
basicjava
Background
The var keyword reduces boilerplate while maintaining compile-time type safety in Java.
Problem
Use var for local variable declarations where the type is obvious from the initializer.
Input
Variable declarations
Output
Type-inferred variables
Sample tests
Sample 1
Input: var list = new ArrayList<String>()
Expected: ArrayList<String> inferred
Your solution
Learning objective
Learn Java 10+ type inference and best practices