String in Java
String in Java
----------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~STRING IN
JAVA~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
Case 1-
String s=" "; //we are allocating a memory to the String
type variable
String s1=Null;//We are just declaring a String type
variable
Case 2-
String s ="ABC";
String s1="ABC";
sop(s==s1); //it always compare the
refence address of two variable.
sop(s.equals(s1)); //equals() - it is use to compare
the content of two different objects of a string type.
Case 3-
String s="Java";
s.concat("class");
sop(s)
o/p- Java // Becouse String type variable are
immutables.
Case 4-
String s1="Java";
String s2= new String("Java");
sop(s1==s2); //output- false
*refence is different.
sop(s1.equals(s2)); //output- True
*Content is same.
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~TYPES OF
CONSTRUCTOR~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
1. Default Constructor :
public String()
eg:
String obj=new string();
2. Parameterised Constructor :
public String(String)
eg:
String obj=new
String("Aman");
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
Q :WAP where you have to take a string from User which contain number and character
in upper and lower case.
perform : 1. delete all vowels from string.
2. Insert "$" symbol before each and every consonent value.
3. Remove all the integer from the string.
4. Compare each and every word of the string (sort the
string).
5. Print the output in a lower case.
STRING BUILDER
STRING BUFFER
16+length of string