

Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index. Int lastIndexOf(String str, int fromIndex) Returns the index within this string of the rightmost occurrence of the specified substring. Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. Returns the index within this string of the last occurrence of the specified character. Returns a canonical representation for the string object. Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. Returns the index within this string of the first occurrence of the specified substring. Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. Returns the index within this string of the first occurrence of the specified character. Void getChars(int srcBegin, int srcEnd, char dst, int dstBegin)Ĭopies characters from this string into the destination character array. Tests if this string ends with the specified suffix.Ĭompares this string to the specified object.īoolean equalsIgnoreCase(String anotherString)Ĭompares this String to another String, ignoring case considerations.Įncodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.Įncodes this String into a sequence of bytes using the named charset, storing the result into a new byte array. Static String copyValueOf(char data, int offset, int count) Returns a String that represents the character sequence in the array specified. Returns true if and only if this String represents the same sequence of characters as the specified StringBuffer. Returns the character at the specified index.Ĭompares two strings lexicographically, ignoring case differences.Ĭoncatenates the specified string to the end of this string. Here is the list of methods supported by String class − Sr.No. ("The value of the float variable is " +įs = String.format("The value of the float variable is " + Using String's static format() method allows you to create a formatted string that you can reuse, as opposed to a one-time print statement. The String class has an equivalent class method, format(), that returns a String object rather than a PrintStream object. You have printf() and format() methods to print output with formatted numbers. Let us look at the following example − Example Live Demo Strings are more commonly concatenated with the + operator, as in − You can also use the concat() method with string literals, as in − This returns a new string that is string1 with string2 added to it at the end. The String class includes a method for concatenating two strings − The following program is an example of length(), method String class. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object. Methods used to obtain information about an object are known as accessor methods. If there is a necessity to make a lot of modifications to Strings of characters, then you should use String Buffer & String Builder Classes. Note − The String class is immutable, so that once it is created a String object cannot be changed. This will produce the following result − Output String helloString = new String(helloArray) The String class has 11 constructors that allow you to provide the initial value of the string using different sources, such as an array of characters. Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'.Īs with any other object, you can create String objects by using the new keyword and a constructor.

The most direct way to create a string is to write − The Java platform provides the String class to create and manipulate strings. In Java programming language, strings are treated as objects. Strings, which are widely used in Java programming, are a sequence of characters.
