JAVA learning lesson 28th (Common Object API)-String class, apistring

Source: Internet
Author: User

JAVA learning lesson 28th (Common Object API)-String class, apistring

Multithreading has come to an end. You need to back up common object APIs !!!

Developed in the future, the most common object is text, or string.

String type

A string is a special object.

The string cannot be changed once it is initialized.


I. Features

Public class Main {public static void main (String [] args) {Demo1 (); System. out. println ("--------------"); Demo2 ();}/* demonstrate the first definition method of a string and specify the characteristics of the String constant pool */private static void Demo1 () {String s1 = "asd"; s1 = "sd"; // s1 is only a String reference, and the String "asd" itself remains unchanged String s2 = new String ("sdf "); system. out. println (s1); s2 = "sd"; System. out. println (s2 = s1); // the address that s1 and s2 actually point to. // sd is stored in the buffer zone (String constant pool) // if not, it is created, do not create}/* demonstrate the second definition of the String, */public static void Demo2 () {String s = "abc "; // create an object String s1 = new String ("abc") in the String constant pool; // the object is not created in the String constant pool, create two objects in heap memory // One is s1 and the other is abc System. out. println (s = s1); // false. The compare address value is different from that of System. out. println (s. equals (s1 )); // true/* The equals in the String class rewrites the equals in the Object and creates the String class * self-determining whether the String Object is the same * that is, comparing the String content */System. out. println ("s =" + s); System. out. println ("s1 =" + s1 );}}

Ii. Constructor

Public class Main {public static void main (String [] args) {StringconstructorDemo1 (); charDemo () ;}public static void StringconstructorDemo1 () {String s = new String (); // equivalent to String s = ""; the address value is different. It is not equivalent to String s = nullbyte [] sub = {97,66}; String s1 = new String (sub); System. out. println ("s1 =" + s1);} public static void charDemo () {char [] ch = {'A', 'B', 'C', 'D ', 'E', 'F'}; String string = new String (ch); // convert the array into a String, which can only be byte and charSystem. out. println ("string =" + string); String string1 = new String (ch,); // The System is truncated from the 0-angle mark. out. println ("string1 =" + string1); // The remaining methods of the String class, check the manual}

Not complete ....




The classes in java are incredibly invincible. I am a newbie and now I feel very hard to learn. How can I learn the API class libraries in java to be more efficient?

Coding. I learned Java from scratch.
From a small program such as helloworld, I personally typed the code at 1.1,
When using the Notepad program, check the APIS one by one, read the API method instructions, and program the program on your own.
I have knocked on countless codes, and now I can find the classes and methods in the API directly.

In Java, what are common StringBuilder APIs, Integer APIs, and Double APIs?

Search for "Java jdk api 1.6.0 Chinese Version documentation" on baidu and download the api.
To learn java, you must learn to view APIs. Otherwise, you will always follow others.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.