As an object, a String variable name is not a simple data type—it is a reference; that is, a variable that holds a memory address. Therefore, when you compare two Strings using the == operator; you are not comparing their values, but their computer memory locations.
Three classes provide you with many methods that make working with characters and strings easier:
(1). Character- A class whose instances can hold a single character value. This class also defines methods that can manipulate or inspect single-character data.
(2). String – A class for working with fixed-string data – that is, unchanging data composed of multiple characters.
(3). StringBuilder and StringBuffer – Classes for storing and manipulating changeable data composed of multiple characters.
The Character class is defined in java.lang and is automatically imported into every program you write. Te Characters class inherits from java.lang.Object.
本文介绍了Java中处理字符串和字符的三个主要类:Character、String 和 StringBuilder/StringBuffer。Character 类用于处理单个字符,String 类适用于固定字符串数据,而 StringBuilder 和 StringBuffer 则用于可变的字符数据。此外还解释了使用 == 操作符比较 String 对象时的误区。
1354

被折叠的 条评论
为什么被折叠?



