Imran_Mohammed

String_in_java_1

Apr 18th, 2022 (edited)
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. import static java.lang.Integer.max;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class NewClass1 {
  7.    
  8.     public static void main(String[] args){
  9.        
  10.         //String Declaration :
  11.         String s1 = "Imran Mohammed";
  12.         String s2 = new String("imran mohammed");
  13.        
  14.         System.out.println(s1);
  15.         System.out.println(s2);
  16.        
  17.        
  18.         //Finding Length :
  19.         int len = s1.length();
  20.         System.out.println(len);//14
  21.        
  22.        
  23.         //Check Equality (Object)
  24.         if(s1 == s2){
  25.             System.out.println("String are equal");
  26.         }
  27.         else{
  28.             System.out.println("String are not equal");
  29.         }
  30.        
  31.         //Check Equality With case
  32.         if(s1.equals(s2) ){
  33.             System.out.println("String are equal");
  34.         }
  35.         if(s1.contains(s2)){
  36.             System.out.println("String are equal");
  37.         }
  38.        
  39.         //Check Equality Ignoring case :
  40.         if(s1.equalsIgnoreCase(s2)){
  41.             System.out.println("String are equal");
  42.         }
  43.        
  44.        
  45.         //Check String Contain or not :
  46.         boolean con = s1.contains("Mohammed");
  47.         System.out.println(con);
  48.        
  49.        
  50.         //Check empty or not :
  51.         boolean b = s1.isEmpty();
  52.         System.out.println(b);
  53.  
  54.  
  55.  
  56.     //String Declaration :
  57.         String s1 = "Imran Mohammed ";
  58.         String s2 = new String("Sanvi");
  59.        
  60.        
  61.         //String Concatation :
  62.         String s3 = s1.concat(s2);
  63.         System.out.println(s3);
  64.        
  65.        
  66.         //Convert Uppercase :
  67.         String uppername = s3.toUpperCase();
  68.         System.out.println(uppername);
  69.        
  70.        
  71.         //Convert Lowerrcase :
  72.         String lowername = s3.toLowerCase();
  73.         System.out.println(lowername);
  74.        
  75.        
  76.         //Check Start with Something :
  77.         boolean b = s1.startsWith("I");
  78.         System.out.println(b);
  79.        
  80.         //Check end with Something :
  81.         boolean l = s1.endsWith("d");
  82.         System.out.println(l);
  83.  
  84.  
  85.     }          
  86. }
  87.  
Add Comment
Please, Sign In to add comment