In java, String is a final class. which is inherit from object class.
we can use final keyword against variable, function and class. if you use final keyword against a variable, then the variable will be constant.
if you use final keyword against class, then it can not be inherited, and if you use it against function , then you cannot be overridden the function.
So from above discussion, we can say String is a class which cannot be inherited .
a) Creation of String :
String s= "hello"
b) Calculate length of the String
int l= s.length();
c) Access the element with respect of index:
char c= s.charAt(i), where i represents the index
if you want access all the element from a string then we can use either use for loop or for-each loop
ex. for loop
for(i=0;i<s.length();i++)
{
System.out.print(s.charAt(i));
}
d) Convert String to Character Array
Char t[]=s.tocharArray();
Thank you, keep learning
0 Comments:
Post a Comment
If you have any doubts . Please let me know.