简体   繁体   English

Arraylist和参数Java

[英]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) (不要过多地使用词汇)

  1. add(Object elem) Adds the object parameter to the list . add(Object elem)将 object 参数添加到列表中

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”

  1. remove(int index) Removes the object at the index parameter . remove(int index)删除索引参数处的 object

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 作为参数/参数传递。

  1. contains(Object elem) Returns 'true' if there's a match for the object parameter contains(Object elem)如果 object 参数匹配,则返回“true”

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中的“索引”是该参数的名称。

传安 ArrayList<customobject> 到接受 ArrayList 作为参数的 function<object> 在 Java<div id="text_translate"><p> 我正在编写一个通用的 java-android function,它将接受ArrayList<Object>作为其参数之一,这样我就可以在我的整个应用程序中使用,而不管 ArrayList 元素的类型如何。</p><p> 这是我的 function:</p><pre> public GenericDisplayAdapter(Activity activity, ArrayList<Object> arrData) { this.m_ArrData = arrData; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); }</pre><p> 当我尝试将我的ArrayList<CustomObject>作为参数传递给此 function 时,出现错误“无法从ArrayList<CustomObject>转换为ArrayList<Object> ”,</p><pre> m_LVStructDamageHeader.setAdapter(new GenericDisplayAdapter( (Activity)this, (ArrayList<Object>)arrStructDamageHeaders));</pre><p> 处理这种情况的最佳方法是什么,谢谢</p></div></object></customobject> - Pass An ArrayList<CustomObject> to a function that accepts as parameter an ArrayList<Object> in Java

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Java 中将 ArrayList 作为参数传递 - Pass ArrayList as parameter in Java Java ArrayList <Double> 作为参数 - Java ArrayList<Double> as Parameter Java - ArrayList <Integer>作为参数......? - Java - ArrayList<Integer> as Parameter…? 在Java中将ArrayList作为泛型参数传递 - Passing ArrayList as generics parameter in Java 发送 Java arraylist 作为 JavaScript 参数 - Send Java arraylist as JavaScript parameter Java-ArrayList <E> 功能参数 - Java - ArrayList<E> Parameter in function Java ArrayList <JTextField> 作为Java方法的参数 - Java ArrayList<JTextField> as parameter on Java method 传安 ArrayList<customobject> 到接受 ArrayList 作为参数的 function<object> 在 Java<div id="text_translate"><p> 我正在编写一个通用的 java-android function,它将接受ArrayList<Object>作为其参数之一,这样我就可以在我的整个应用程序中使用,而不管 ArrayList 元素的类型如何。</p><p> 这是我的 function:</p><pre> public GenericDisplayAdapter(Activity activity, ArrayList<Object> arrData) { this.m_ArrData = arrData; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); }</pre><p> 当我尝试将我的ArrayList<CustomObject>作为参数传递给此 function 时,出现错误“无法从ArrayList<CustomObject>转换为ArrayList<Object> ”,</p><pre> m_LVStructDamageHeader.setAdapter(new GenericDisplayAdapter( (Activity)this, (ArrayList<Object>)arrStructDamageHeaders));</pre><p> 处理这种情况的最佳方法是什么,谢谢</p></div></object></customobject> - Pass An ArrayList<CustomObject> to a function that accepts as parameter an ArrayList<Object> in Java 传递新的 ArrayList 与传递 ArrayList 作为函数(Java)中的参数 - Passing new ArrayList vs Passing ArrayList as a parameter in Function(Java) Java中的参数传递(ArrayList与整数) - Parameter Passing (ArrayList vs Integer) in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM