1 / 24

Unit-2 Objects and Classes

Unit-2 Objects and Classes. String Class. String Class. A string is a sequence of characters. In many languages, strings are treated as an array of characters, but in Java a string is an object. The String class has 11 constructors and more than 40 methods for manipulating strings.

leia
Download Presentation

Unit-2 Objects and Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit-2 Objects and Classes String Class

  2. String Class • A string is a sequence of characters. • In many languages, strings are treated as an array of characters, • but in Java a string is an object. • The String class has 11 constructors and more than 40 methods for manipulating strings.

  3. Constructing a String

  4. Immutable Strings and Interned Strings

  5. String Comparisons

  6. String Comparisons(Cont.) Using equals Function:

  7. String Comparisons(Cont.) Using compare To Function:

  8. Program(Equal to & Compare TO)

  9. Program(regionMatches() )

  10. Program (endWith)

  11. Program (startWith)

  12. String Length, Characters, and Combining Strings • The String class provides the methods for obtaining length, retrieving individual characters, and concatenating strings.

  13. Program

  14. Obtaining Substrings • You can also obtain a substring from a string using the substring method in the String class.

  15. Example

  16. Converting, Replacing, and Splitting Strings • The String class provides the methods for converting, replacing, and splitting strings, as shown in Figure.

  17. Program

  18. Example(Split () )

  19. String Matching

  20. Finding a Character or a Substring in a String • The String class provides several overloaded indexOf and lastIndexOf methods to find a character or a substring in a string.

  21. Program

  22. Conversion between Strings and Arrays

  23. Formatting Strings

  24. Converting Characters and Numeric Values to Strings • There are several overloaded versions of the valueOf method that can be used to convert a character and numeric values to strings with different parameter types, char, double, long, int, and float.

More Related