Using var for Local Variables in Java


The var keyword can simplify variable declarations with less verbosity while maintaining readability.

Source Code

public class VarExample {
    public static void main(String[] args) {
        var list = new ArrayList(); // infers ArrayList
        var stream = list.stream(); // infers Stream
        System.out.println(stream);
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments