Java Reference
In-Depth Information
a = new int[10];
⇒
Allocates in main memory space for 10 integers.
Returns the
i
th
element of the array, where counting starts at 0.
a[i]
⇒
a.length
⇒
Returns the length of the array.
{
}
⇒
Creates and populates the array.
int [] a =
2,4,6,3
;
⇒
A for-each
for
loop that iterates through the elements of
for(int element: a)
an array of integers.
m(new int[]
{
2,3,4
}
);
⇒
Passes an anonymous array of integers to the method.
int[][] a = new int[10][20];
⇒
Creates a two-dimensional array of integers with
10 rows and 20 columns.
⇒
a[2][3]
Refers to the element at row 2 and column 3. Both row and column
counting starts at position 0.
a[0].length
⇒
Number of columns in row 0 of the two-dimensional array.
a.length
⇒
Number of rows in a two-dimensional array.
int[][] a =
{{
1,2
}
,
{
2
}}
;
⇒
Creates a two-dimensional ragged array. The first
row has the numbers
{
1,2
}
, while the second row has the number
{
2
}
.
int[][][] a;
⇒
Creates a three-dimensional array.
StringTokenizer st = new StringTokenizer(s)
⇒
Creates a new string tokenizer
from the
String s
.
Returns the number of tokens in the string tokenizer. Space
and new line are used as the default delimiters.
⇒
st.countTokens()
⇒
Returns
true
if there are more tokens.
st.hasMoreTokens()
⇒
Returns the next token as a
String
.
st.nextToken()
public static void m(int
...
a)
The signature of a method that takes as input
a variable number of integers. In the method, the variable
a
is used as though an array
was passed to the method. An array of integers can also be passed to the method.
⇒
⇒
The variable
args
is the array of
public static void main(String[] args)
strings that is passed as input to the program.
int[] b = Arrray.copyOf(a,a.length);
⇒
Makes a deep copy of the
a
array and
saves it in the
b
array.
Arrays.equals(a,b);
⇒
Returns true if the two arrays have the same size and
elements.