
正文
java中的字符串String
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、String简介d
参考:https://www.cnblogs.com/zhangyinhua/p/7689974.html
String类代表字符串。 java.lang.String:
Java程序中的所有字符串文字(例如"abc" )都被实现为此类的实例。 字符串String的值在创建后不能被更改
String源码
/** String的属性值 */
private final char value[]; /** The offset is the first index of the storage that is used. */
/**数组被使用的开始位置**/
private final int offset; /** The count is the number of characters in the String. */
/**String中元素的个数**/
private final int count; /** Cache the hash code for the string */
/**String类型的hash值**/
private int hash; // Default to 0 /** use serialVersionUID from JDK 1.0.2 for interoperability */
private static final long serialVersionUID = -6849794470754667710L;
/**
* Class String is special cased within the Serialization Stream Protocol.
*
* A String instance is written into an ObjectOutputStream according to
* <a href="{@docRoot}/../platform/serialization/spec/output.html">
* Object Serialization Specification, Section 6.2, "Stream Elements"</a>
*/ private static final ObjectStreamField[] serialPersistentFields =
new ObjectStreamField[0];
创建字符串的3+1种方式:
public String(); 创建一个空白字符串
public String(char[] array); 根据字符数组的内容,来创建对应的字符串
public String(byte[] array); 根据字节数组的内容,来创建对应的字符串 一种直接创建







