Lecture note Java methods A & AB: Object-oriented programming and data structures: Chapter 10 - Maria Litvin, Gary Litvin

Chapter 10 - Strings. In this chapter, the learning objectives are: Learn about literal strings, learn about string constructors and commonly used methods, understand immutability of strings, learn to format numbers into strings and extract numbers from strings, learn several useful methods of the Character class, learn about the StringBuffer class. | Strings Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. "Chapter 10" 10- Processing text is what computers do much of the time. Your Java compiler is one example of a program that does a lot of handling and parsing of strings. Handling strings is pretty straightforward and convenient in Java. Objectives: Learn about literal strings Learn about String constructors and commonly used methods Understand immutability of strings Learn to format numbers into strings and extract numbers from strings Learn several useful methods of the Character class Learn about the StringBuffer class 10- The char data type is not in the AP Java subset, while strings are. However, any reasonable course will teach chars. One of the reasons for excluding char from the subset was the perceived danger of confusing a char constant 'x' with a string constant "x". An . | Strings Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. "Chapter 10" 10- Processing text is what computers do much of the time. Your Java compiler is one example of a program that does a lot of handling and parsing of strings. Handling strings is pretty straightforward and convenient in Java. Objectives: Learn about literal strings Learn about String constructors and commonly used methods Understand immutability of strings Learn to format numbers into strings and extract numbers from strings Learn several useful methods of the Character class Learn about the StringBuffer class 10- The char data type is not in the AP Java subset, while strings are. However, any reasonable course will teach chars. One of the reasons for excluding char from the subset was the perceived danger of confusing a char constant 'x' with a string constant "x". An unstated objective of this chapter is to get a clear understanding that char and String are two different data types. char is a primitive data type; Strings are objects. The String class An object of the String class represents a string of characters. The String class belongs to the package, which is built into Java. Like other classes, String has constructors and methods. Unlike other classes, String has two operators, + and += (used for concatenation). 10- There is no need to import because the package is imported automatically into all classes. Like the char type, String objects internally represent characters using Unicode. The + and += operators for strings are an exception in Java, the only example of operators that work with objects. Literal Strings Literal strings are anonymous constant objects of the String class that are defined as text in double quotes. Literal strings don’t have to be constructed: they are “just there.” 10- This is

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.