是字符串数组可变的? [英] Are String Arrays mutable?
本文介绍了是字符串数组可变的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道是否在Java中的字符串数组是可变的?我知道,字符串是不可改变的,但如何对字符串数组?
I wonder if String arrays in Java are mutable ? I know that Strings are immutable, but how about string Arrays ?
如果我有一个字符串数组,并更改内容,将一个新的字符串对象创建?或将实际值只是改变?
If I have a string array, and change the content, will a new string object be created ? Or will the actual value just be changed ?
在此先感谢
推荐答案
的字符串
取值包含在的String []
确实是不可变的,但数组是可变的。
The String
s contained in the String[]
are indeed immutable, but the array is mutable.
这是很好的解释这个答案:
- 不变性是指特定类型的对象可以以任何有意义的方式向外部观察者不会改变
-
整数
,字符串
等都是不可变 - 一般来说所有的值类型应
- Immutability means that objects of a certain type can not change in any meaningful way to outside observers
Integer
,String
, etc are immutable- Generally all value types should be
- 这可能是不可改变的类型的引用数组,但数组本身是可变的
- 这意味着你可以设置为任何这些引用你想
- 同样适用原语阵列
- 如果对象是可变的,突变将通过所有这些引用可以看出
编辑:
这篇关于是字符串数组可变的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-
查看全文