[英]Arraylist and parameter Java
From my understanding A method uses parameters, A caller passes arguments.据我了解A方法使用参数,调用者传递arguments。 And i am just learning about arraylist
我只是在学习 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. add(Object elem) 将object 参数添加到列表中。
remove(int index) Removes the object at the index parameter. remove(int index) 删除index 参数处的 object。
remove(Object elem) Removes this object (if it's in the ArrayList). remove(Object elem) 删除此 object(如果它在 ArrayList 中)。
contains(Object elem) Returns 'true' if there's a match for the object parameter contains(Object elem) 如果object 参数匹配,则返回“true”
isEmpty() Returns 'true' if the list has no elements isEmpty() 如果列表没有元素,则返回 'true'
indexOf(Object elem) Returns either the index of the object parameter , or -1 indexOf(Object elem) 返回object 参数的索引,或 -1
size() Returns the number of elements currently in the list size() 返回当前列表中的元素个数
get(int index) Returns the object currently at the index parameter get(int index) 返回当前在index 参数处的 object
I am confused what does object parameter and index parameter means??我很困惑object参数和索引参数是什么意思??
Parameter and argument are basically different names of same thing.参数和参数基本上是同一事物的不同名称。 (Not going too much into vocabulary)
(不要过多地使用词汇)
As the desc.正如描述。 says, you have a list of objects and you want to add another object.
说,你有一个对象列表,你想添加另一个 object。 So you pass that object to be added as a parameter to the method "add"
因此,您将 object 作为参数传递给方法“add”
Here you want to remove an object from your list of objects.在这里,您要从对象列表中删除 object。 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.
现在 java 列表索引从 0 开始。假设您要删除索引 1 处的 object。然后调用方法“remove”并将 1 作为参数/参数传递。
Here you want to check if an object defined by "elem" is present in your list.在这里,您要检查列表中是否存在由“elem”定义的 object。 So you call the "contains" method passing the "elem" variable (of type object) which returns true if the list contains that object else false.
因此,您调用“包含”方法传递“elem”变量(对象类型),如果列表包含 object,则返回 true,否则返回 false。
And so on...等等...
Parameter is the argument we pass to a method.参数是我们传递给方法的参数。 'object' in
object parameter
is simply the name of the parameter. object parameter
中的 'object' 只是参数的名称。 Similarly 'index' in index parameter
is the name of that parameter.同样,
index parameter
中的“索引”是该参数的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.