dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Aug 6, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Java StringWriter

StringWriter is similar to StringBuffer, which can collect a host of string values and work with the data. We will explore writing a porting of a given string.

Code sample:

import java.io.StringWriter;

public class UsingStringWriter
{
   public static void main(String args[])
   {
      UsingStringWriter usingStringWriter = new UsingStringWriter();
      usingStringWriter.proceed();
   }
   
   private void proceed()
   {
      String welcomeString = "Welcome";
      
      StringWriter stringWriter = new StringWriter();
      
      stringWriter.write(welcomeString);
      System.out.println(stringWriter.toString());
   }
}

/*

Expected output:

[root@mypc]# java UsingStringWriter
Welcome

*/
M S Sridhar
 
Thanks for your registration, follow us on our social networks to keep up-to-date