Strings in java and its function

1.string is non primitive datatype
2.string are immutable
3.initialization:-There are two ways
   a)Using a string literal  
     String  A="sourcecode";
   b)Using new Keyword
     String B = new String("sourcecode");
4.Most important function in String:-
        1) char charAt(int index) :-its passes the value where index point it .
        2) int length()   :-its return the lenth of string
        3) int substring(int beginIndex)  :-its return character till index rich
        4) int substring(int beginIndex,int Index) :-its return character start from beginning index and end on end index
        5) boolean contains(charsequence)  :-see example below
        6) boolean equals(object another)  :-its return true or false whether two strings are equal or not.
        7) boolean isEmpty()    :-its return true or false whether the string is empty or not.
        8) String concat  :-its add the two string
        9) String replace(char old,char new)  :-its replace the character in a string
        10) String[] split(string regex)
        11) int indexOf(int ch)  :-its determine the index
        12) String toLowerCase()
        13) String toUpperCase()
All above string function executed below

package Loops;
import java.util.Scanner;
public class strings {                                   
    public static void main(String[] args) {
       String name="sourcecodejava";             
       System.out.println(name);
       System.out.println("charAt function :");
       System.out.println(name.charAt(2)); 
       System.out.println("lenghth function :");
       System.out.println(name.length()); 
       System.out.println("substring function :");
       System.out.println(name.substring(5));
       System.out.println(name.substring(2,5));
       System.out.println("the strings contains source? "+name.contains("source"));
       String name2="sourcecodejava";
       System.out.println("the two strings are equal?? "+name.equals(name2));
       System.out.println("the string name is empty?? "+name.isEmpty());
       System.out.println("concat function: ");
       System.out.println(name.concat(" blog"));
       System.out.println(name.replace('c','s'));
       String carsbrand="maruti,swift,hundai,bmw";
       System.out.println("split function :");
       String allcar[]=carsbrand.split(",");
       for(String car:allcar) {
       System.out.println(car);
      }
       System.out.println("indexOf function example :");
       System.out.println(+name.indexOf("o"));
       System.out.println("toLowerCase function:");
       System.out.println(name.toLowerCase());
       System.out.println("toUpperCase function:");
       System.out.println(name.toUpperCase());
      
    }
}
expected output:-

sourcecodejava
charAt function :
u
lenghth function :
14
substring function :
ecodejava
urc
the strings contains source? true
the two strings are equal?? true
the string name is empty?? false
concat function:
sourcecodejava blog
soursesodejava
split function :
maruti
swift
hundai
bmw
indexOf function example :
1
toLowerCase function:
sourcecodejava
toUpperCase function:
SOURCECODEJAVA

Comments