Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Create a StringBuffer object using a reference stored in a variable of type String in Java
To create a StringBuffer Object, we use the following syntax −
StringBuffer s=new StringBuffer();
When we create a reference to an object, we use the assignment operator. For example,
String s1 = ”hi”; String s2 = s1; // s2 is a reference of s1
A program to illustrate the creation of a StringBuffer object using a reference stored in a variable of type String is given below −
Example
public class Example {
public static void main(String args[]) {
String input = "hey";
String s1 = input; // creating a reference of the String
StringBuffer s = new StringBuffer(s1);
System.out.println(s);
}
}
Output
The output is as follows −
Hey
Advertisements
