简体   繁体   English

List 方法结合初始化一个新的 object

[英]List Method in combination with initializing a new object

in my course i am actually at Lists and how to work with them.在我的课程中,我实际上是在 Lists 以及如何使用它们。 There is one command i dont fully get.有一个命令我没有完全理解。 I think the topic lists is pretty roff so please go easy on me.我认为主题列表很简单,所以请 go 放轻松。

Person node = list.remove(0);人节点 = list.remove(0);

Person is the Class node the new Oject Person 是 Class 节点新 Oject

What is inside of node now is what were inside of list.(index 0), why is that, didn't i remove what is inside of the list?现在节点内部的内容是列表内部的内容。(索引0),为什么会这样,我没有删除列表内部的内容吗? Can i handle it the same way like:我可以像这样处理它吗:

Person node = list.get(0);人节点 = list.get(0); list.remove(0); list.remove(0);

Person node = list.get(0); 
list.remove(0);

is equivalent to:相当于:

Person node = list.remove(0);

It is how the method is defined in the List interface.这是在List接口中定义方法的方式。 When you remove, the method also returns the Object removed.当您删除时,该方法还会返回已删除的 Object。 More in docs here: https://docs.oracle.com/javase/8/docs/api/java/util/List.html#remove-int-更多文档在这里: https://docs.oracle.com/javase/8/docs/api/java/util/List.html#remove-int-

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

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