Advertisement
wadkat

java strings methods

Nov 1st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package lesson1;
  6.  
  7. /**
  8. *
  9. * @author pclab
  10. */
  11. public class stringmethods {
  12. public static void main(String[] args)
  13. {
  14. String str1="Burger", str2="King";
  15. String str3="BURGER", str4="burger";
  16.  
  17. System.out.println("Length of str1:"+str1.length());
  18. System.out.println("Length of str2:"+str2.length());
  19.  
  20. System.out.println("Substring method:"+str4.substring(2, 6));
  21. System.out.println("Substring method:"+str3.substring(3));
  22.  
  23. System.out.println("to lower case:"+str3.toLowerCase());
  24. System.out.println("to upper case:"+str4.toUpperCase());
  25.  
  26. System.out.println("Equals method:"+str3.equals(str4));
  27. System.out.println("Equals Ignorecase mehod:"+str3.equalsIgnoreCase(str4));
  28.  
  29. System.out.println("Index of a:"+str4.indexOf('a'));
  30. System.out.println("Last index of a:"+str4.lastIndexOf('a'));
  31.  
  32. String str5 = str1 + " "+str2;
  33. System.out.println(str5);
  34. System.out.println("String 5 Length: "+str5.length());
  35.  
  36. System.out.println(str3.compareTo(str4);
  37. System.out.println(str4.compareTo(str3);
  38. System.out.println(str3.compareTo(str3);
  39.  
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement