简体   繁体   中英

Arraylist and parameter Java

From my understanding A method uses parameters, A caller passes arguments. And i am just learning about arraylist

what i cant understand is what parameter means in the following syntax the bold ones

add(Object elem) Adds the object parameter to the list.

remove(int index) Removes the object at the index parameter.

remove(Object elem) Removes this object (if it's in the ArrayList).

contains(Object elem) Returns 'true' if there's a match for the object parameter

isEmpty() Returns 'true' if the list has no elements

indexOf(Object elem) Returns either the index of the object parameter , or -1

size() Returns the number of elements currently in the list

get(int index) Returns the object currently at the index parameter

I am confused what does object parameter and index parameter means??

Parameter and argument are basically different names of same thing. (Not going too much into vocabulary)

  1. add(Object elem) Adds the object parameter to the list .

As the desc. says, you have a list of objects and you want to add another object. So you pass that object to be added as a parameter to the method "add"

  1. remove(int index) Removes the object at the index parameter .

Here you want to remove an object from your list of objects. Now java list index starts from 0. Suppose you want to remove the object at index 1. Then you call the method "remove" and pass 1 as argument/parameter.

  1. contains(Object elem) Returns 'true' if there's a match for the object parameter

Here you want to check if an object defined by "elem" is present in your list. So you call the "contains" method passing the "elem" variable (of type object) which returns true if the list contains that object else false.

And so on...

Parameter is the argument we pass to a method. 'object' in object parameter is simply the name of the parameter. Similarly 'index' in index parameter is the name of that parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM