PersonHandler.java 917B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Created by leon on 1/24/18.
  3. */
  4. public class PersonHandler {
  5. private final Person[] personArray;
  6. public PersonHandler(Person[] personArray) {
  7. this.personArray = personArray;
  8. }
  9. public String whileLoop() {
  10. String result = "";
  11. int i = 0;
  12. while (i < personArray.length){
  13. result += personArray[i].toString();
  14. i++;
  15. }
  16. return result;
  17. }
  18. public String forLoop() {
  19. String result = "";
  20. for (int i = 0; i < personArray.length; i++) {
  21. result += personArray[i].toString();
  22. }
  23. return result;
  24. }
  25. public String forEachLoop() {
  26. String result = "";
  27. for (Person person : personArray) {
  28. result += person.toString();
  29. }
  30. return result;
  31. }
  32. public Person[] getPersonArray() {
  33. return personArray;
  34. }
  35. }