Array - data structure that allows us to store multiple values of the same type into a single variable
Default value - zero
Arrays are zero indexed - Array with ten elements will be indexed from 0 to 9
Array[]
How to create array:
boolean type arrays - default value is false
Errors while working with arrays
How to print out simple int array?
Default value - zero
Arrays are zero indexed - Array with ten elements will be indexed from 0 to 9
Array[]
How to create array:
- int[] array = new int[5]; (boxes have value zero - secured slot in memory to hold values)
- int[] myArray = {1,2,3,4,5}; this type of initializing an array is also known as an anonymous array
boolean type arrays - default value is false
Errors while working with arrays
- ArrayIndexOutOfBoundsExeption
int[] my Array = {10,35,45,78,55}
- myArray[5] = 55; out of bound
- index 5 does not exist
- int[] myArray = {10,15,20,17,18};
System.out.println("value= " + myArray[i]
it will return values from index 1
How to print out simple int array?
example:
int[] myArray = new int[2];myArray[0]=0;myArray[1]=1;
System.out.println("My array: " + Arrays.toString(myArray));
static String | toString(int[] a)
Returns a string representation of the contents of the specified array.
|
public class Arrays - This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
Komentarze
Prześlij komentarz