Great Deals

String Demo

12:42 Unknown 0 Comments


public class StringDemo {

       public static void main(String[] args) {
       String s=new String("Shiv");
      
       char firstChar=s.charAt(0);
       System.out.println("First Charecter"+firstChar);
      
       boolean status=s.contains("i");
       if(status){
              System.out.println("i Found");
       }else{
              System.out.println("i Not Found");
       }

       status=s.endsWith("iv");
       if(status){
              System.out.println("ends with iv");
       }else{
              System.out.println(" Not ends with iv");
       }

       String newString=s.replace('v', 'V');
                     System.out.println("Replaced= "+newString);
      
       String name="Ajju";
       System.out.println("Last Occurance of J= "+name.lastIndexOf("j"));
       System.out.println("First Occurance of J= "+name.indexOf("j"));
       //**Substring starting from point 2*/
       System.out.println("SubString"+name.substring(2));
      
       name="Java is Great";
      
       String []words=name.split(" ");
      
       for(String oneWord:words)
       {
              System.out.println(""+oneWord);
       }
      
       }
      
      
}


0 comments:

Advertising