

State the purpose and return data type of the following String functions: Two exception handling blocks are try and catch. What is exception? Name two exception handling blocks.Īn exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. It extracts a part of the string as specified by its arguments and returns the extracted part as a new string. It returns a character from the string at the index specified as its argument
DISPLAY MENU VICE CITY CODE
Output of this code snippet will be HELLO. Output of this code snippet will be hello. ToLowerCase() and toUpperCase() toLowerCase()Ĭonverts all characters of the String object to lower caseĬonverts all characters of the String object to upper case The result is true if the contents are same otherwise it is false. The result is a negative, positive or zero integer value depending on whether the String object precedes, follows or is equal to the String argument It checks if contents of two strings are same or not. It compares two strings lexicographically. The output of this code snippet is false as s1 and s2 point to different String objects. The output of this code snippet is true as contents of s1 and s2 are the same. It is used to check if two variables refer to the same object in memory It is used to check if the contents of two strings are same or not Differentiate between the following Question 1

substring( 0, 3)) Output falseĪs length of the string "DELHI" is less than that of "LUCKNOW" so first output is false.Īrr.substring(0,3) will return the substring of "JAIPUR" starting at index 0 till index 2 (i.e. Give the output of the following statements: concat() method joins "Computer" and "Applications" together to give the output as ComputerApplications. m.substring(9) returns the substring of m starting at index 9 till the end of the string which is "Applications". N.substring(0,8) returns the substring of n starting at index 0 till 7 (i.e. (iv) (x.equals(y)) Output falseĪs strings x and y are not equal so x.equals(y) returns false. This is added to the end of string y and printed to the console as output. X.substring(5) will return the substring of x starting at index 5 till the end of the string. (iii) (y + x.substring(5)) Output Applicationster First index of 'u' in x is 4 so output is 4. X.charAt(4) returns the character at index 4 of string x which is 'u'. X.substring(1,5) will return a substring of x starting at index 1 till index 4 (i.e.

Computer World equals COMPUTER WORLD false Computer World equals Computer world false Computer World equals computer world false Computer World equalsIgnoreCase computer world true ExplanationĪs the strings S1, S2, S3 and S4 differ in the case of the characters so equals() method will return false but equalsIgnoreCase() method will return true.
