Page 263 - Cs_withBlue_J_C11_Flipbook
P. 263

The indexOf(char ch, int index) Function
                 For a string variable, this function returns the index value of the given character present in the string of the current
                 String object starting from the index provided in the parameter. It returns an integer type value. The syntax is:

                    int <variable> = String_datatype_Variable.indexOf(char ch, int index);
                 Let us see the below example:

                    String str= "Computer Science";
                    int position= str.indexOf('c',11);
                    System.out.println("The index value is: " + position);
                 Output:
                 The index value is: 14

                 The lastIndexOf(char ch) Function
                 For a string variable, this function  returns the index value of the last existence of the given character present in the
                 string of the current String object. It returns an integer type value. The syntax is:

                    int <variable> = String_datatype_Variable.lastIndexOf(char ch);
                 Let us see the below example:

                    String str= "Computer Science";
                    int position= str.lastIndexOf('e');
                    System.out.println("The index value is: " +position);
                 Output:
                 The index value is: 15

                 The toLowerCase() Function
                 As the name itself suggests, this function  converts the given string to the corresponding string in lowercase letters.
                 However, for any letters written in lowercase, there will be no change in the output. The syntax is:
                    String <variable> = String_datatype_Variable.toLowerCase();
                 Let us see the below example:
                    String str= "KOLkatA - 700114";
                    String changestr= str.toLowerCase();
                    System.out.println("The converted string is: " +changestr);
                 Output:
                 The converted string is: kolkata - 700114


                 The toUpperCase() Function
                 This method converts the given string to the corresponding string in upper case letters. However, for the letters already
                 in upper case, there will be no change in the output. The syntax is:

                    String <variable> = String_datatype_Variable.toUpperCase();
                 Let us see the below example:
                    String str= "KOLkatA - 700114";

                    String changestr= str.toUpperCase();
                    System.out.println("The converted string is: " +changestr);
                 Output:

                 The converted string is: KOLKATA – 700114


                                                                                                                       261
                                                                                                              Strings  261
   258   259   260   261   262   263   264   265   266   267   268