Thursday, 3 July 2014

append (Object obj)

public synchronized StringBuffer append(Object obj)
Appends the string representation of the Object argument.

class Student{
    int id;
    String name;
    
    Student(int id, String name){
        this.id = id;
        this.name = name;
    }
    
    @Override
    public String toString(){
        return id + "." + name;
    }
}

public class StringBufferAppendObject {
    public static void main(String args[]){
        StringBuffer s1 = new StringBuffer("Value of s1 is ");
        Student stud = new Student(1, "Hari");

        s1.append(stud);
  
        System.out.println(s1);
    }
}

Output
Value of s1 is 1.Hari



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment