tailieunhanh - Lecture Fundamentals of computing 1: Lecture 7 - Duy Tan University
Lecture Fundamentals of computing 1: Lecture 7 introduce the strings. This chapter presents the following content: Immutable string, immutable string string comparison, string concatenation, substring, commonly used methods of string class, stringbuffer classs, commonly used methods of stringbuffer class, stringbuilder classs, commonly used methods of stringbuilder class, tostring(). | Lecture Title: Strings Fundamentals of Computing 1 Agenda Strings Immutable String String Comparison String Concatenation subString Commonly used Methods of String class StringBuffer classs Commonly used Methods of StringBuffer class StringBuilder classs Commonly used Methods of StringBuilder class toString() ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) String Generally string is a sequence of characters. But in java, string is an object. String class is used to create string object. String Handling provides a lot of concepts that can be performed on a string such as concatinating string, comparing string, substring etc. In java, string is basically an immutable object. We will discuss about immutable string later. Lets first understand what is string and how we can create the string object. The String class How to create String object? There are two ways to create String object: By string literal By new keyword By String literal String literal is created by double quote. Ex1: String s="Hello"; S “Hello” String constant pool Heap Each time you create a string literal, the JVM checks the string constant pool first. If the string already exists in the pool, a reference to the pooled instance returns. If the string does not exist in the pool, a new String object instantiates, then is placed in the pool. By String literal (cont.) Ex2: String s1=“Welcome"; String s2=" Welcome "; Note: String objects are stored in a special memory area known as string constant pool inside the Heap memory. S2 S1 “Welcome” String constant pool Heap In the above example only one object will be created. First time JVM will find no string object with the name "Welcome" in string constant pool, so it will create a new object. Second time it will find the string with the name "Welcome" in string constant pool, so it will not create new object whether will return the reference to the same instance. Question . | Lecture Title: Strings Fundamentals of Computing 1 Agenda Strings Immutable String String Comparison String Concatenation subString Commonly used Methods of String class StringBuffer classs Commonly used Methods of StringBuffer class StringBuilder classs Commonly used Methods of StringBuilder class toString() ask them, how might the computer store "hi" using binary digits? (some kind of mapping; ASCII) String Generally string is a sequence of characters. But in java, string is an object. String class is used to create string object. String Handling provides a lot of concepts that can be performed on a string such as concatinating string, comparing string, substring etc. In java, string is basically an immutable object. We will discuss about immutable string later. Lets first understand what is string and how we can create the string object. The String class How to create String object? There are two ways to create String object: By string literal By new keyword By .
đang nạp các trang xem trước