Zusammenfassung der Ressource
Array
- Very similar to dictionaries in Python
- The size of an array can't be change
- How to declare/instantiate: elementType[] varName = new elementType[arraySize];
- Example:String[] stringHolder = new String[5]
- Setting the values of an array: varName[index] = value;
- Checking the length: varName.length (no parentheses)
- Can also initialize it like this: String[] stringHolder = {value1, value2, value3}
- Indexing through an array: for-each loop
- Example: for(elementType element: nameofArray)
- for(double d1: stringHolder)
- Two Dimensional Arrays
- Declare: int[][] array2d;
- array2d = new int[3][10]
- Copying Arrays:
- Use a loop to copy the individual elements
- use static arraycopy method in System class
- arraycopy(sourceArray, sourcePosition, targetArray, targetPosition, length)
- Use clone method to copy arrays.