Thursday, 7 January 2021

Java10: Define an array using var

Following syntax is used to define an array.

 

Syntax

var arrayName = new dataType[]{}

 

Example

var primes = new int[] {2, 3, 5, 7}

jshell> var primes = new int[] {2, 3, 5, 7}
primes ==> int[4] { 2, 3, 5, 7 }

jshell> primes[0]
$2 ==> 2

jshell> primes[2]
$3 ==> 5

jshell>

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment