Syntax

Java Infer a Local Type Syntax

In Java, infer a local type: lets the compiler infer a local variable's type — var list = new ArrayList<String>();

Quick Answer

Syntax
var list = new ArrayList<String>();
JavaSyntax

Infer a Local Type

Code example
var list = new ArrayList<String>();

Lets the compiler infer a local variable's type.

Learn More

How to infer a local type in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java Infer a Local Type Syntax

Use var list = new ArrayList<String>();.

Related Syntax References

Frequently asked questions

What is the Java syntax for infer a local type?

Use this pattern: var list = new ArrayList<String>();

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify