多少个对象与数组产生的? [考试] [英] How many objects are created with an Array? [Java]

查看:144
本文介绍了多少个对象与数组产生的? [考试]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道有多少对象,这个阵列产生的?

Hello I would like to know how many objects are created with this array?

String arr[] = {"Paul", "Steven", "Jennifer", "Bart"};

在此先感谢!

推荐答案

创建九对象。

每个字符串是两个对象。字符串引用和字符串的基本的char [] 。因此,对于四弦,这是8个目标。

Each String is TWO objects. The String reference, and the String's underlying char[]. So for 4 strings, that's 8 objects.

那么,有的String [] 本身共有9。

这当然是由JVM假定字符串文字一直没有实习生() ED呢。如果有,那么就不会创建字符串,而是从实习生拉池,这可能给你一共有1,3,5,7,或创建原始9的对象,这取决于有多少字符串实习生编辑。

This of course assumes the String literal has not been intern()ed yet by the JVM. If it has, then it will not create the String, but instead pull it from the intern pool, which could give you a total of 1, 3, 5, 7, or the original 9 objects created, depending on how many Strings are interned.

这篇关于多少个对象与数组产生的? [考试]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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