fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. ArrayList<String> b = new ArrayList<>();
  13. b.add("dog");
  14. b.add("cat");
  15. b.add("bird");
  16. b.add("rabbit");
  17.  
  18. // Find the largest (lexicographically last) string
  19. String x = b.get(0);
  20. for (int i = 1; i < b.size(); i++) {
  21. if (b.get(i).compareTo(x) > 0) {
  22. x = b.get(i);
  23. }
  24. }
  25.  
  26. // Output the result
  27. System.out.println("The lexicographically largest string is: " + x);
  28. }
  29. }
Success #stdin #stdout 0.13s 55400KB
stdin
Standard input is empty
stdout
The lexicographically largest string is: rabbit