REMEMBER JAVA

MINTE9
2REMEMBER




Always object

Regardless of what the array holds, the array itself is always an object.
 RunCode
class LearningApp {
    public static void main(String[] args) {
        
        int[] nums;
        nums = new int[3];
        nums[0] = 1;
        nums[1] = 2;
        nums[2] = 3;
        System.out.println(nums[2]); // 3

        String[] names = {"John", "Marry", "Ana"}; // {} array object
        System.out.println(names[2]); // Ana

        nums[3] = "abc";  // Compile Error - Look Here
    }
}
... 13 lines
˄˄˄

Types

p83 In this example we don't create a new Dog object. We create an Array by Dog types values.
 RunCode
class LearningApp {
    public static void main(String[] args) {
    
        Dog[] dogs = new Dog[4]; // array of Dogs
        dogs[0] = new Dog();
        dogs[1] = 2; // Compiler Error 
    }
}

class Dog {}
... 8 lines
˄˄˄

Join

Starting with Java 8 we can use String.join() method.
 RunCode
public class LearningApp {

    public static void main(String[] args) {
        
        String[] letters = new String[] {"a", "b", "c"};

        String joined = String.join(", ", letters); // Look Here

        System.out.println(joined); // a, b, c
    }
}
... 7 lines
˄˄˄
Task

 CompleteTask
class LearningApp {

    public static void main(String[] args) {

        /**
         * Create an array nums of integers ...
         * The array must have the length = 3 ...
         * First element nums[0] should display 100
         * Remember that array declaration must be fixed length
         */

        ...
    }
}
solution code
Questions    
No. 4   Variables
CARD
03
63

        A B C D E F
🔔
1/2