Wednesday, 30 May 2012

Wednesday (May 30 '2012)

Today, @HCL  i was taught STRINGS in java. At the end of today's class, i was able to do String Manipulation, which is the most common part of many Java programs. Now, i know which package is imported to perform String related functions in a Java program, and how to use functions like- Concatenation of 2 strings, changing case of strings, replacing a part or whole of the string with another set of characters, how to display a sub-string , finding the length of a string and comparison of 2 strings.

Examples:

1. Concatenation of 2 strings.

              import java.lang.String;
            public class String1
               {
                 public static void main(String args[])
                    {
                      String S = " Java " ;
                      String R = " Core " ;
                      String T = (S.concat(R));
                 System.out.println(T);
                     }
                }

OUTPUT: Java Core


2. Replacing characters in a string.

                    
import java.lang.String;
            public class String2
               {
                 public static void main(String args[])
                    {
                      String S = "Hydrophobia" ;
                      R = S .replace ("o" , "a");
                  System.out.println(R);
                     }
                }
 
OUTPUT: Hydraphabia

3. Displaying a Sub-string.
     
                      import java.lang.String;
            public class String3
               {
                 public static void main(String args[])
                    {
                      String S = "Hydrophobia" ;
                      R = S .substring (1,5);
                  System.out.println(R);
                     }
                }

 OUTPUT: ydro
          



                    
  

No comments:

Post a Comment