Examples of smaller Java programs that do various interesting things.

IntListTesterVer2.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. public class IntListTesterVer2 {
  2. public static void main(String[] args){
  3. IntListVer2 list1 = new IntListVer2();
  4. IntListVer2 list2 = new IntListVer2(100);
  5. //equal when empty?
  6. System.out.println("list1.equals(list2): " + list1.equals(list2));
  7. System.out.println("list1: " + list1);
  8. System.out.println("list2: " + list2);
  9. //add elements
  10. for(int i = 0; i < 100; i += 5){
  11. list1.add(i);
  12. list2.add(i);
  13. }
  14. System.out.println("list1.equals(list2): " + list1.equals(list2));
  15. System.out.println("list1: " + list1);
  16. System.out.println("list2: " + list2);
  17. list2.add(200);
  18. System.out.println("Added 200 to list2.");
  19. System.out.println("list1.equals(list2): " + list1.equals(list2));
  20. System.out.println("list1: " + list1);
  21. System.out.println("list2: " + list2);
  22. System.out.println("Testing efficieny of StringBuffer versus using String.");
  23. System.out.println("Increasing list1 size to 10000.");
  24. Stopwatch s = new Stopwatch();
  25. list1 = new IntListVer2();
  26. for(int i = 0; i < 10000; i++)
  27. list1.add(i);
  28. s.start();
  29. list1.toString();
  30. s.stop();
  31. System.out.println("Time to build String using String class: " + s.toString() );
  32. s.start();
  33. list1.toStringUsingStringBuffer();
  34. s.stop();
  35. System.out.println("Time to build String using StringBuffer class: " + s.toString() );
  36. }
  37. }