Following are the major differences between these 2: • String is immutable as compared to StringBuffer. You need to create a new instance to replace an object. Java Code: This is an example of immutable string //Inefficient version using immutable String String output = “Some text” Int count = 100; for(int I =0; i<count; i++) { output += i; } return output; • StringBuffer is mutable. Also it is not synchronized. Java Code: This is an example of mutable string //More ...
//Inefficient version using immutable String String output = “Some text” Int count = 100; for(int I =0; i<count; i++) { output += i; } return output;
//More
Updated 01-14-2012 at 06:42 PM by Java String
Its always useful to wrap strings if they are too long. This provides better readability. Eclipse has support for this. String literals can wrapped when you edit them. Place your cursor at the point of literal where you want to wrap and press Enter. For example: Java Code: String message= "Java is fun to learn and it sure is a popular programming language."; I kept the cursor at ‘sure’ and pressed enter key. The String was changed to: ...
String message= "Java is fun to learn and it sure is a popular programming language.";
thanks...
sorry for all the questions
thanks...
06-14-2013, 02:22 PM in gbonecapone