Exploring the String class

Although the String class will be examined in depth in Part II of this book, a short exploration of it is warranted now, because we will be using strings in some of the example programs shown toward the end of Part I. String is probably the most
commonly used class in Java’s class library. The obvious reason for this is that strings  are a very important part of programming The first thing to understand about strings is that every string you create is actually an object of type String. Even string constants are actually String objects. For example in the statement.the string This is a String, too” is a String constant. Fortunately, Java handles String constants in the same way that other computer languages handle “normal” strings, so  you don’t have to worry about this.The second thing to understand about strings is that objects of type String are immutable; once a String object is created, its contents’ cannot be altered, While this may seem like’a serious restriction, it is not, for two reasons .

The String class contains several methods that you can use. Hearer few. You can
test two strings for equality by using You can obtain the length of a string by calling the  method obtain the character at 11 specified index within a string by calling The  forms of these three methods are shown here.

reCAPTCHA is required.

Share This