Primitive array和Reference Array有什么区别? [英] What is the difference Between Primitive array and Array of Reference .

查看:52
本文介绍了Primitive array和Reference Array有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了net和Found引用数组存储引用.从某种意义上说,引用是要存储变量的内存地址,我猜如果我没记错的话.如果是这种情况,为什么当我如下遍历字符串数组时看不到内存地址.

I read in net and Found reference array store references. References in sense the array is going to store memory address of variables i Guess if i am not mistaken. If that's the Case why i don't see the memory address when i loop through string array as Below.

  String[] arrNames = new String[3];
  arrNames[0]       = "John";
  arrNames[1]       = "Mac";
  arrNames[2]       = "Alex";

现在按照定义,arrNames数组将把引用存储在arrNames [0],arrNames [1],arrNames [2]处.这意味着内存地址将指向名称,即John,Max和Alex.

Now as per the definition the arrNames array is going to store References at arrNames[0],arrNames[1], arrNames[2]. Which means memory address which is going to point to Names i.eJohn, Max and Alex.

如果它是基本数组,则将直接存储如下所示的值.

If it is Primitive array its directly going to store the values like below.

 int[] Num = new int[3];
 Num[0]    = 1;
 Num[1]    = 2;
 Num[2]    = 3;

数字[0]直接保留数字1而不是指向数字的地址.

The Num[0] is directly going to hold Numbers 1 instead of address which points to number.

如果我误解了,请纠正我.

Please correct me if i misunderstood it.

推荐答案

在Java中,没有原始数组.即使我们在数组中具有原始值,但数组本身仍被视为数组对象.

In java there is no primitive array. Even though we had the primitive values in an array, then the array itself considered as array object.

这篇关于Primitive array和Reference Array有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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