![]() The output of "VIDYALAYA".substring(2,5) will result in DYA Write down the syntax to perform the following tasks Question 1 The return type of the statement equals( ) is boolean. Question 6Ĭharacter literal is enclosed within single quotes ('). String declaration is terminated by the symbol semicolon ( ). Plus ( + ) operator is used to concatenate two strings. The output of the statement, when executed: The output of the following statement, when executed: Fill in the blanks Question 1Ĭoncat() method is used to join two strings. Reason - Java Class Library contains a class called String which is available under java.lang package. Which of the following packages contain string functions? So, output of compareTo() method will be ASCII Code of 'A' - ASCII Code of 'I' ⇒ 65 - 73 ⇒ -8. "AMAN" and "AMIT" differ at the third character with 'A' and 'I', respectively. Reason - compareTo() returns a negative value if the first string is smaller than the second string in terms of the ASCII values of the corresponding characters. So, the two strings will not be considered equal and the boolean value 'false' will be returned. Reason - equals() method treats uppercase and lowercase characters differently. What will be the output of the following program snippet? Reason - trim( ) function is used to remove leading and trailing white spaces from the string. Which of the following functions is used to remove leading and trailing white spaces from the string? So, the given statement is solved as follows: Since P is at 3 rd position so indexOf('P') will return 3 and charAt(3) function will return the character at the third index i.e., 'P'. Reason - charAt(int index) returns a character from the given index of the string and indexOf(char ch) returns the index of first occurrence of a character in the string. What will be the value stored in the variable 'c' if the following statement is executed?Ĭ = "COMPUTER".charAt("COMPUTER ".indexOf('P')) Hence, the last index will be 11 (12-1), as 12 is the size of the string. Hence, the index number of the characters starts from 0 (zero) and ends with (k-1), if k is length of the string. Reason - A String data type manages character array for storing a string character-wise starting from 0 th subscript. If a string contains 12 characters, what will be the index of the last character? Reason - String data type creates a character array to store a set of characters in different cells. Reason - A string literal may consist of a set of letters, a set of letters and digits or a set of letters, digits and special characters. A set of letters, digits and special characters.Throws IndexOutOfBoundsException if the beginIndex is negative, or endIndex is larger than the length of the string, or beginIndex is larger than endIndex. If beginIndex equals endIndex, the method returns an empty string. The substring starts with the character at the specified beginIndex and extends to the end of the string or up to endIndex - 1 if the second argument is given. beginIndex: the starting index, inclusive. str.substring(int beginIndex, int endIndex) The substring() method of Java's String class returns a new string that is a substring of the given string.Ģ. In this guide, you will learn about the String substring() method in Java programming and how to use it with an example.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |