Object Oriented Programming-1 (Lab Sesion-6)


  • Explore below three classes of java


  1. String Class
  2. StringBuffer Class
  3. StringBuilder Class


Learn how String can be constructed using all these classes. Write a sample program to create String with all three classes.


Solution :

Code :

package .vscode;

public class Compare_String { 

    public static void string(String s1) { 
        S1 = s1 + “OrientedProgram”; 
    } 
    
    public static void stringbuilder(StringBuilder s2) { 
        S2.append(“OrientedProgram”); 
    } 

    public static void stringbuffer(StringBuffer s3) {
        S3.append(“OrientedProgram”); 
    } 

    public static void main(String[] args) { 

        String s1 = “Object”; 
        String(s1);  
        System.out.println(“String: “ + s1); 

        StringBuilder s2 = new StringBuilder(“Object”);        stringbuilder(s2); 
        System.out.println(“StringBuilder: “ + s2); 

        StringBuffer s3 = new StringBuffer(“Object”); 
        Stringbuffer(s3); 
        System.out.println(“StringBuffer: “ + s3); 
    } 
}


OUTPUT:

 

DOWNLOAD PDF HERE........


No comments:

Post a Comment