Differences between equals and = in Java
= Compare the addresses of two objects, while equals compares the content of two objects.
Obviously, when equals is true, ==is not necessarily set to true;
The importance of basic knowledge is expected to attract everyone's attention, including yourself.
Many puzzles and questions come from the most basic knowledge.
After a while, I checked the books and finally got some insights on the special object
One, String class String class in the Java.lang package, Java uses the string class to create a string variable that belongs to the object. The final class declared by the Java String class cannot have a class. A string class ob
The difference between the Equals method used by string and = =The difference between the Equals method and = = First you know that string can be used as an object or as a base type. This refers to use as a basic type only refers to the use of methods, such as String s = "H
(): Displays the string as subscript.SUP (): Displays the string as superscript.toLowerCase (): Converts a string to lowercase.toUpperCase (): Converts a string to uppercase.Fixed (): Displays a string in typewriter text.FontColor (): Displays a
("ill") in the second half and cannot be determined during the compilation period; if you understand this, you will know why this result is obtained.
4. String. Intern ():
Another note: the constant pool exists in the. Class file and is loaded by JVM at runtime and can be expanded. The intern () method of string is a met
conversions must be performed before the conversion.The instanceof operator is used to indicate at run time whether an object is an instance of a particular class. Instanceof is indicated by returning a Boolean value,Whether this object is an instance of this particular class or its subclassesThe tostring method, which returns the string representation of the object, is actually the type of the object [ema
Method attribute of the string objectString (String object)I am not a master. I just want to write this section down for you to see. The real String object is really useful. Hey, I hope you can share it with me ..The following is an example of the tutorial.A String object is
String Class
1. Initialization of String objects
Because string objects are particularly common, Java provides a simplified special syntax when initializing a string object, in the following format:
String s = "abc";
s = "Java language";
In fact, according to the object-ori
String method, return value, whether to change the original string:The 1charAt () method returns the character at the specified position.Do not change the original stringJavaScript does not have a character data type that differs from a string type, and the returned character is a
String teststr = "Western-style lighting is popular to enjoy the luxury of the taste"; teststr = Teststr.replaceall ("[|]", ""). Trim ();As shown in the code, directly replace all the full-width spaces in the string with a half-width space, and then use the trim () method.Site editors often accidentally switch between full-width and half-width, resulting in a lot of news text containing two kinds of spaces
Tostringpublic string toString () returns a string representation of the object. Typically, the ToString method returns a string that represents this object in text format. The result should be a concise but easy to read. It is recommended that all subclasses override this method.The ToString
Learning a language string and array methods is a must to learnIn detail, i'll give you a little bit of reference.String Type Basics
Character literal
The String data type contains some special character literals, also known as escape sequences (characters with special Meaning)
Literal quantity
Meaning
\ n
Line break
\ t
Tabs
character within the original string, find the first, return its index value, not found return-1Note is looking from left to right , find the first , like here O, in the original string has more than one, but only returns the index value of the first, in addition, when the given character is more than one, the first character of the given string as the datum poi
Method Summary
char
charAt(intindex)ReturnscharValue.
int
codePointAt(intindex)Returns the characters (UNICODE code points) at the specified index ).
int
codePointBefore(intindex)Returns the character (UNICODE Code Point) before the specified index ).
int
codePointCount(intbeginIndex, intendIndex)Return thisStringNumber of Unicode code points in the specified text range.
int
compareTo(Stringa
API:
Public String intern () returns the canonicalized representation of the string object.
A string pool that is null at the beginning, which is privately maintained by the string class.
When the intern method is called, if the pool already contains a
know why the result is obtained.4. String.intern ():One more point: the constant pool that exists in the. class file is loaded by the JVM at run time and can be expanded. The Intern () method of string is a method of extending a constant pool, and when a string instance str calls the Intern ()
JAVA learning lesson 30th (Common Object API)-String class: Class Method exercises, apistring
Intern Method
Public class Main {public static void main (String [] args) {String str1 = new String ("asd");
Chapter III strings, comparators and filters
Some of the methods introduced by JDK are useful for writing code that is functional style. Some of the classes and interfaces in the JDK library we've been very familiar with, like string, we have to proactively look for opportunities to use these new methods in order to get rid of the old style we used to be. Again, when we need to use an anonymous inner class with only one
StringUnicode sequenceThe string is immutableDefinition of string: Supports subscript operation, supports slicing operation, supports unpacking, packet operation .s = ' magedu ' Method of String: join: Join (...) S.join (iterable), str uses S to stitch up each character element of an iterative object (only the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.