一、String简介d
参考:https://www.cnblogs.com/zhangyinhua/p/7689974.html
String类代表字符串。 java.lang.String:
Java程序中的所有字符串文字(例如"abc" )都被实现为此类的实例。 字符串String的值在创建后不能被更改
String源码
1 /** String的属性值 */ 2 private final char value[]; 3 4 /** The offset is the first index of the storage that is used. */ 5 /**数组被使用的开始位置**/ 6 private final int offset; 7 8 /** The count is the number of characters in the String. */ 9 /**String中元素的个数**/ 10 private final int count; 11 12 /** Cache the hash code for the string */ 13 /**String类型的hash值**/ 14 private int hash; // Default to 0 15 16 /** use serialVersionUID from JDK 1.0.2 for interoperability */ 17 private static final long serialVersionUID = -6849794470754667710L; 18 /** 19 * Class String is special cased within the Serialization Stream Protocol. 20 * 21 * A String instance is written into an ObjectOutputStream according to 22 * <a href="{@docRoot}/../platform/serialization/spec/output.html"> 23 * Object Serialization Specification, Section 6.2, "Stream Elements"</a> 24 */ 25 26 private static final ObjectStreamField[] serialPersistentFields = 27 new ObjectStreamField[0];
创建字符串的3+1种方式:
public String(); 创建一个空白字符串
public String(char[] array); 根据字符数组的内容,来创建对应的字符串
public String(byte[] array); 根据字节数组的内容,来创建对应的字符串 一种直接创建
原文地址:https://www.cnblogs.com/liufeng1618/p/12158707.html
时间: 2024-11-10 07:37:08