Posts

Showing posts with the label Q & A

How to create String, StringBuffer and StringBuilder in java

Image
Most of the data transmits on Internet will be in the form of group of characters. Such group of characters are called as 'String'. JavaSoft people have created a class separately with the name of 'String' in java.lang package with all necessary methods to work with String.           Even though, String class, it is used often in the form of a data type, as String s = "Java" ; Creating String:           There are 3 ways to create String in java.               • We can create a String just by assigning a group of characters to String type variable String s ; // Declare String type variable s = "Java" ; // Assign a group of charecters to it           Preceding two statements can be combined and written here, String s = "Java" ;           In this case JVM creates an object and stores the string: "Java" in that object. This object referenced by the string variable 's'.