what is Object reference type (String) ? its method & string comparing!!

Object Reference Type (String)

String are a sequence of characters, in the JAVA programming String are object. the JAVA platform provide the String class to create and manipulate String. String class is encapsulated under Java.lang package string act s a datatype.

Syntax :- 
        
String variable_name = new String();

or

String variable_name = "value";

ex :-  

creating string using new keyword.

String str = new string("vismyblog");

or

creating a string using string literals.

String str = "vishmyblog";

basic String Methods :-

1 )- to uppercase(String) :-
to uppercase method, it will converts all the characters into uppercase.

2 )- to lowercase(String) :-

to lowercase method, it will converts all the characters into small case.

3 )- trim() :-

It removes the white space between two strings and before and after the string.

4)- length() :-

It will count positive no. of characters.

5 )- replace() :-

It replaces all the occurrence of the first sequence with the other sequence.

6 )- value of() :-

It converts any given data type such as int, long, short, double, float, byte, char, Boolean into string datatype.


 String Comparison :-

It can be done in the different ways.

1 )- equal to:- 

This method compress two String for equality, it compress the content of the string . if the string matches it return true else return false.

2 )- double equals to (==) :-

The double equals to operator compare two object reference to check whether they refer to same instance, this will also return true or false.

3 )- Compare to() :- 

The method compare to compares the value and return integer, which tells if the string Compare is less than equals to &  greater than equals to or any alphabetical order.









Post a Comment

0 Comments