Professional Documents
Culture Documents
See : https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html
public class StringConcatenate{
public static void main(String[] args){
long startTime = System.currentTimeMillis();
for(int i=0;i<5000;i++){
String result = "This is"
+ "testing the"
+ "difference"+ "between"
CONCATENATE T WO STRINGS
+ "String"+ "and"+ "StringBuffer";
}
long endTime = System.currentTimeMillis();
String buffers are safe for use by multiple System.out.println("Time taken for string"
threads. The methods are synchronized where + "concatenation using + operator : "
necessary so that all the operations on any + (endTime - startTime)+ " ms");
long startTime1 = System.currentTimeMillis();
particular instance behave as if they occur in
for(int i=0;i<5000;i++){
some serial order that is consistent with the StringBuffer result = new StringBuffer();
order of the method calls made by each of the result.append("This is");
individual threads involved. result.append("testing the");
The principal operations on a StringBuffer are result.append("difference");
the append and insert methods, which are result.append("between");
overloaded so as to accept data of any type. result.append("String");
Each effectively converts a given datum to a result.append("and");
string and then appends or inserts the result.append("StringBuffer");
characters of that string to the string buffer. }
The append method always adds these long endTime1 = System.currentTimeMillis();
System.out.println("Time taken for String concatenation"
characters at the end of the buffer; the insert
+ "using StringBuffer : "
method adds the characters at a specified + (endTime1 - startTime1)+ " ms");
point. }
}
GET UNICODE OF STRINGS public class StringUniCode{
public static void main(String[] args){
codePointBefore(int i) String test_string="Welcome to TutorialsPoint";