在Java中,String是一个字符数组吗? [英] In Java, is a String an array of chars?

查看:204
本文介绍了在Java中,String是一个字符数组吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果 String 是一个集合。我已阅读但仍然很困惑。

I want to know, if a String is a collection. I have read around but am still quite confused.

推荐答案

字符串是不可变的对象代表字符序列 CharSequence 是String实现的接口之一)。
字符数组和字符集合的主要区别:字符串无法修改,无法(忽略反射)添加/删除/替换字符。

Strings are immutable objects representing a character sequence (CharSequence is one of the interfaces implemented by String). Main difference to char arrays and collections of chars: String cannot be modified, it's not possible (ignoring reflection) to add/remove/replace characters.

内部它们由字符数组 表示偏移量长度(这允许创建轻量级子字符串,使用相同的char数组)。

Internally they are represented by a char array with an offset and length (this allows to create lightweight substrings, using the same char arrays).

示例:['F','o','o','H','e','l','l' ,'o','','W','o','r','l','d'],offset = 3,count = 5 = Hello

Example: ['F','o','o','H','e','l','l','o',' ','W','o','r','l','d'], offset=3, count=5 = "Hello".

这篇关于在Java中,String是一个字符数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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