Page 419 - CA_Blue( J )_Class10
P. 419

method is:

                    int <variable> = <String_Object>.indexOf(char ch);
                 For example:

                    String str = "Computer Science";
                    int v = str.indexOf('p');
                    System.out.println("The index value is: " +v);
                 You will get the following output:
                 The index value is: 3

                 The indexOf() method has an overloaded method which takes the character to be find and the starting index from
                 where the searching starts as parameters. It returns integer type of value. Syntax to use this method is:

                    int <variable> = <String_Object>.indexOf(char ch, int index);
                 For example:
                    String str = "Computer Science";
                    int v = str.indexOf('e',9);
                    System.out.println("The index value is: " +v);
                 You will get the following output:

                 The index value is: 12

                 16.3.4 The lastIndexOf() Method
                 The lastIndexOf() method returns the index of the last occurrence of the character passed as parameter in the current
                 String object. It returns integer type of value.
                    int <variable> = <String_Object>.lastIndexOf(char ch);
                 For example:

                    String str= "Computer Science";
                    int v= str.lastIndexOf('e');
                    System.out.println("The index value is: " +v);
                 You will get the following output:
                 The index value is: 15

                 16.3.5 The toLowerCase() Method
                 The toLowerCase()  method  converts  the String  to small  letters.  It returns a String  value.  The syntax to use the
                 toLowerCase() method is:

                    String <variable> = <String_Object>.toLowerCase();
                 For example:

                    String str = "KOLkatA - 700114";
                    String changestr= str.toLowerCase();
                    System.out.println("The converted string is: " +changestr);
                 You will get the following output:
                 The converted string is: kolkata - 700114


                       Note: If the String contains any small letters or digits or special characters, then there will be no
                       change.







                                                                                                                       417
                                                                                                       String Handling  417
   414   415   416   417   418   419   420   421   422   423   424