Java String

Page 1

JAVA STRING www.java2blog.com


CONTENT Overview String class String Constant pool StringBuffer class StringBuilder class

PROJECT PROPOSAL


OVERVIEW A string is an object which shows the sequence of characters. In Java, we can create a string using three classes String, StringBuffer, StringBuilder. All these classes implement the CharSequence interface.

PROJECT PROPOSAL


STRING CLASS String class is present in java.lang package. String class provides a lot of methods for performing the operations on the strings. we can create String object using two ways: By new keyword By using String literal. PROJECT PROPOSAL


STRING CLASS If we create String Object through the new keyword. JVM will create String object into the Heap memory. String str1=new String("Good Morning");

If we create String object using String literal, JVM will store it into the String constant pool. String str2="Good morning"; PROJECT PROPOSAL


CONSTANT POOL String constant pool is a special memory area which is a part of Heap memory. When we create String object using String literal, JVM first checks if String is already available in the String constant pool. If it exists, JVM will create only reference to it. If it does not exist, JVM will create new String object and store it in String constant pool. PROJECT PROPOSAL


STRINGBUFFER CLASS StringBuffer class is used to create a mutable string. Mutable String is a string that can be modified. It is synchronized class, i.e, Multiple threads can't invoke the StringBuffer class methods simultaneously. StringBuffer str1= StringBuffer("Welcome");

PROJECT PROPOSAL


STRINGBUILDER CLASS StringBuilder class is used to create mutable strings. It is a non-synchronized class, i.e., Multiple threads can call methods of StringBuilder simultaneously. StringBuilder str2=new StringBuilder("Welcome");

PROJECT PROPOSAL


DIFFERENCES The important difference between String, StringBuffer, and StringBuilder class is: String class is an immutable whereas StringBuffer and StringBuilder classes are mutable. StringBuffer class is thread-safe while StringBuilder class is not thread-safe class. PROJECT PROPOSAL


THANK YOU www.java2blog.com


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.