Page 257 - IT-802_class_12
P. 257

Output:
            The character is: a

            The int indexOf(char ch) method
            For a string variable, this method returns the index value of the first position of the given character passed as an
            argument in the String object. It returns an integer type value. The syntax is:

              int <variable> = String_datatype_Variable.indexOf(char ch);
            Let us see the below example:
              String str= “Computer Science”;
              int position = str.indexOf(‘p’);

              System.out.println(“The index value is: “ + position);
            Output:
            The index value is: 3
            The int 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 String toLowerCase() method
            As the name itself suggests, this method 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 String toUpperCase() method
            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();

                                                                               Fundamentals of Java Programming  255
   252   253   254   255   256   257   258   259   260   261   262