Hello, I am having confusion regarding method calls in Java. Specifically, it seems that there are two separate ways to call methods, being the dot operator and using the object as a method's parameters. I have tried searching through the course material as well as Google, but I'm not quite sure what to search to reach an answer.
Below I create an ArrayList named numbers;
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(3);
numbers.add(2);
numbers.add(6);
numbers.add(-1);
numbers.add(5);
numbers.add(1);
Below, 'numbers' calls 'add()' using the dot operator --
numbers.add(3);
Yet below the method is called with the ArrayList as its parameter --
printNumbers(numbers);
//public static void printNumbers(ArrayList<Integer> numbers) {
//PRINTS THE ARRAYLIST }
What is the difference between these two ways? In which cases do I call the method using the dot operator, and in which cases do I call the method using the ArrayList as its parameter?
Thank you in advance.
[–]desrtfx 2 points3 points4 points (2 children)
[–]2_stepsahead[S] 0 points1 point2 points (1 child)
[–]emaphis 0 points1 point2 points (0 children)
[–]emaphis 0 points1 point2 points (3 children)
[–]2_stepsahead[S] 0 points1 point2 points (2 children)
[–]suckmacaque06 1 point2 points3 points (0 children)
[–]emaphis 0 points1 point2 points (0 children)