Append Function in Java

Ads
 

Append Function in Java

What is the use of append function in java? How to use the append function to append a string to a buffer string.

Thanks

View Answers

January 27, 2013 at 2:03 PM

You can use the StringBuffer class in Java to efficiently append the string. This is very efficient method of appending string in Java. Once all the string is appended to the StringBuffer object you can get the final string through calling the toString() on the StringBufferobject. Use StringBuffer is very good and provides good performance if in your application you are appending string multiple times. The class StringBuffer provides the following the necessary function for appending the string.

sb.append("myString");

Here is the complete code of the Java Append example:

import java.io.*;

public class appendFunctionJava 
{
    public static void main(String[] args) 
    {
        System.out.println("Append fuction in Java");

        String finalString; 
        StringBuffer sb = new StringBuffer(100); 
        //Append string
        sb.append("line 1: Example of Append Fuction in Java.\n");
        sb.append("Appended Line 2:\n");
        sb.append("Appended Line 2:\n");

        finalString = sb.toString(); 
        System.out.println("Final String is: " + finalString); 


    }
}

Thanks

Ads









Related Tutorials/Questions & Answers:
Append Function in Java
Append Function in Java  What is the use of append function in java? How to use the append function to append a string to a buffer string. Thanks   You can use the StringBuffer class in Java to efficiently append
How to Append String In Java?
How to Append String In Java?  How to write program in in Java for appending to a String? How to Append String In Java? What is the best way to do this? Thanks   Hi, The best best to append to a string is to use
Advertisements
How to append String in Java?
How to append String in Java?  Hi, I have a number of string in Java which is to be appended efficiently. How to append String in Java? Thanks... efficiently and then get final string. The append() of the class is used
how to write append file in Java
how to write append file in Java  How to write append file in Java   Hi, For append in the test new file or Appending a text earlier... in an existing files. For this in java program we uses WriteToFileAppend.java to be used
How to append text to an existing file in Java
How to append text to an existing file in Java  How to append text to an existing file in Java
How To Append String In Java
How To Append String In Java In this section we will read about how to append... a simple example. There are various ways to append String in Java. Below, we will describe it one by one : The first and easy way to append string in Java
In Java I have append to an existing string efficiently
In Java I have append to an existing string efficiently  Hi, In a Java program I have to append to a existing string more efficiently so... of the cases. Check the example at: How To Append String In Java?. Thanks
java password function
java password function  secret password function
Append To File - Java Tutorial
Append To File - Java Tutorial     ... and BufferedWriter to append the data to a file.  FileWriter The FileWriter is a class... of the constructor) then the constructor append the specified data to the file i.e.
Write a program in Java to append content at the end of an already existing file.
Write a program in Java to append content at the end of an already existing file.  Write a program in Java to append content at the end of an already existing file
function to return value in java
function to return value in java  How to return maximum value in java?   Return Value in Java
hash function for java strings
hash function for java strings  hash function for java strings   int hash=7; for (int i=0; i < strlen; i++) { hash = hash*31+charAt(i
MySQL Append String
MySQL Append String       This example illustrates how to append string of different column. We use CONCAT() function to append the values of columns. In this example
Java Code Color Function Error
Java Code Color Function Error  Java Code Color Function Error
function arguments in java
function arguments in java  function arguments in java   Command line argument in Java import java.util.*; public class SumAndAverage... of Numbers: "+sum/10); } }   command line argument in Java - sample
java program to create xml file with append data in well-formed
java program to create xml file with append data in well-formed   Sorry sir your given xml append data program is not well-formed. I'll make you more clear what I want. If this is my xml file Tom Cruise 45 Now when I append
Java append file
Java append file In this section, you will learn how to append the text to the file. This has become a common task. You can easily append any text...: name- file name append- if true, then bytes will be written to the end
Java Function for block inside a block
Java Function for block inside a block  Write a function in Java that attempts to place a set of squares of varying widths into another, larger square. If there is no possible layout, return undefined. Otherwise, return
Java Function for block inside a block
Java Function for block inside a block  Write a function in Java that attempts to place a set of squares of varying widths into another, larger square. If there is no possible layout, return undefined. Otherwise, return
C/C++/JAVA Question on function
C/C++/JAVA Question on function  "Write a function to find out common alphabets between two arrays. Length of array is not fixed and may contain other data type also.ΓΆβ?¬Β? Question can be solved in C,C++ or JAVA
validation of strings using java function
validation of strings using java function  hi all, i am uploading data from csv file to data base where i took student id as string of length 6 char of the form abc123 will you please give me a function to validate this field
java equivalent of c function htonl & htons
java equivalent of c function htonl & htons  hi is there any java equivalent for the c function htonl & htons
Java Write To File Append
Java Write To File Append In this tutorial you will learn how to append...;appenToFile.txt" and write some text. And then create a java file named... in this example is as : FileWriter(String fileName, boolean append); e.g.
Java code to append/add data into a existing xml file
Java code to append/add data into a existing xml file  Java code to append data into a existing xml file, As user enters data it overwrites the previous XML file,I want it to be append the data in XML file rather then overwriting
MySQL Append Data
MySQL Append Data       This example illustrates how to append data with a column value. 'CONCAT()' function is used to append data to the column value
how to call java script function through java class file
how to call java script function through java class file  how to call jframe in java script
function
function  difference between function overloading and operator overloading
Java append new node to XML file
Java append new node to XML file In this tutorial, you will learn how to append new node to xml file. Sometimes there is a need to append a new XML node to the xml file. Here is an xml file where we are going to append a new node
MySQL Append
MySQL Append This example illustrates how to append the value of two column. In this example we use the 'CONCAT' function to append the two values of two column.   Query   SELECT
Error in calling javascript function from java
Error in calling javascript function from java  I am callin javascriot function from applet and getting error netscape.javascript.JSException: Unexpected error: This method should not be used unless loaded from plugin.jar
MySql Append Codes
MySql Append Codes       This example illustrates how to append the column values. We use CONCAT() function to append the values of two column. In this example, we

Ads