0% found this document useful (0 votes)
10 views2 pages

Java Arrays Guide for Beginners

Uploaded by

dhaouadi.eya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Java Arrays Guide for Beginners

Uploaded by

dhaouadi.eya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

ARRAYS: •object that stores values of same type

>elements: values in the array (initial "zero-equivalent" values)


>index[0..n]: to access elements
>n: length-1

------------------------------------------
| • type[] array_name = new type[length]; |
| • type[] array_name = {v1, v2, ...}; |
------------------------------------------

•Access element: array_name[index]


•Modify element: array_name[index]=value;

•length: array_name.length
•arrays are printed with for loops

-----------------------------------------------------------------------------------
--------

♦Arrays class (java.util package):


>array methods:
•Arrays.binarySearch(array, value): index of value in a sorted array (<0 if not
found)
•Arrays.copyOf(array, length): copy of array
•Arrays.equals(array1, array2): check elements of arrays -> true: same order of
elements
•Arrays.fill(array, value): fill all elements with given value
•Arrays.sort(array): arrange elements in ascending order
•Arrays.toString(array): convert array to string "[v1, v2, v3]"

-----------------------------------------------------------------------------------
--------

ARRAYS OF ARRAYS:

♦2-Dimentional Arrays(Matrix):

----------------------------------------------------
| • type[][] array_name = new type[rows][columns]; |
| • type[][] array_name = { |
| {v00, v01, v02 ... } |
| {v10, v11, v12 ... } |
| {v20, v21, v22 ... } |
| } |
----------------------------------------------------

•Access element: array_name[i][j]

•all arrays don't have to be of same length.


•not required to define all arrays.
•length:
>number of arrays: array_name.length
>number of elements of i'th array: array_name[i].length

♦MultiDimentional Arrays:

---------------------------------------------------
| • type[][][].. array_name = new type[x][y][z]..; |
---------------------------------------------------

>same features of 2-dimentional arrays.

-----------------------------------------------------------------------------------
--------

You might also like