什么ArrayList的实际存储 - 引用对象或实际的对象? [英] What does ArrayList actually stores - References to objects or actual objects?

查看:122
本文介绍了什么ArrayList的实际存储 - 引用对象或实际的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我的code是这样的:

Suppose my code goes like this:

ArrayList list = new ArrayList();
Student s = new Student();    // creating object of Student class

myList.add(s);      // Here am confused ...

/* myList contains just the reference variable to the Student object, OR

   myList contains the actual Student object (memory allocation for name, rollNo etc)  ??   
*/

在短片添加对象使用添加到ArrayList的()时:

In Short when adding objects to ArrayList using add():

ArrayList是的参考对象列表或它的一个实际的对象???

ArrayList is a list of "References to objects" or its a list of "actual objects" ???

推荐答案

在Java中,你永远不会绕过实际的对象。你总是处理的引用,它本质上只是一个地址到您的对象被存储在存储器内的一个位置。

In Java, you never pass around actual objects. You are always dealing with references, which is essentially just an address to a location within memory where your object is stored.

因为你从来没有与实际工作的对象,包含的ArrayList存储在别处对象的引用数组(在内存中有个地方叫堆)。

Since you never work with actual objects, ArrayLists contains arrays of references to objects stored somewhere else (a place in memory called the heap).

这篇关于什么ArrayList的实际存储 - 引用对象或实际的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆