để đọc lướt qua vật liệu mà chúng đã biết và tập trung vào những gì mới mẻ đối với họ. Nó có nghĩa là đọc cho tất cả mọi người. Và nó làm cho cuốn sách hướng dẫn tham khảo nhanh chóng và dễ dàng sử dụng khi bạn đang thực hiện đào tạo.(* Để xem các trang kết hợp công việc, bạn có thể tải về chương miễn phí từ trang web murach.) | Chapter 12 How to work with dates and strings 401 The String class Common constructors of the string class Constructor Description string String arrayName String arrayName intoffset intLength Creates an empty string Creates a suing from an array of char or byte types. Creates a string from a subset of an array of char or byte types. Example 1 Two ways to create an empty string string name String name new string Example 2 Two ways to create a string from another string string title Murach s Beginning Java 2 String title bookTitle Example 3 Two ways to create a string from an array of characters char cityArray D f a f l f l f a f s String cỉtyStrỉngl new string cityArray String cityString2 new string cityArray 0 3 Example 4 Two ways to create a string from an array of bytes byte cityArray 68 97 108 108 97 115 String cỉtyStrỉngl new string cityArray String cityString2 new string cityArray 0 3 Notes For the third constructor shown above the characters referred to by the intOffset and intLength arguments must fall within the array. Otherwise the constructor will throw an IndexOutOfBoundsException. A char data type contains a single Unicode character which is stored in two bytes. When you use the second and third constructors above you can construct a String object from an array of char types. To code a literal char value you use single quotes instead of double quotes as shown in the third example. Because a byte data type can hold the Unicode value for every character in the ASCII character set you can also construct a String object from an array of bytes as shown in the fourth example. Since String objects are immutable they can t grow or shrink. Later in this chapter you ll learn how to work with StringBuilder objects that can grow and shrink. Figure 12-7 How to create strings 402 Section 3 More Java essentials Methods of the string class In chapters 2 and 4 you learned how to use the equals and equalsIgnoreCase methods of the String class to compare