fork download
  1.  
  2. class Ideone
  3. {
  4. public static void main (String[] args) throws java.lang.Exception
  5. {
  6. String s1 = " ";
  7. // length / emptiness
  8. System.out.println(s1.length());
  9. System.out.println(s1.isEmpty());
  10. System.out.println(s1.isBlank()); // checks a string other than white spaces
  11.  
  12. String s2 = "Hello";
  13. // character access
  14. System.out.println(s2.charAt(3));
  15. System.out.println(s2.toCharArray());
  16.  
  17. String s3 = "hello";
  18. String s4 = "HELLO";
  19. // comparisons
  20. System.out.println(s3.equals(s4));
  21. System.out.println(s3.equalsIgnoreCase(s4));
  22. System.out.println(s3.compareTo(s4));
  23. // compares the lexicographical values with ASCII
  24. // compareTo -> -ve, 0, +ve
  25. // -ve if s3 is smaller than s4 lexicographically
  26. // 0 if strings are same
  27. // +ve if s3 is greater than s4 lexicographically
  28. System.out.println(s2.compareTo(s3));
  29. }
  30. }
Success #stdin #stdout 0.07s 52536KB
stdin
Standard input is empty
stdout
3
false
true
l
Hello
false
true
32
-32