PersonHandler.java 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. int arr = personArray.length;
  13. while(i < arr){
  14. result += personArray[i].toString();
  15. i++;
  16. }
  17. return result;
  18. }
  19. public String forLoop() {
  20. String result = "";
  21. int arr = personArray.length;
  22. for(int i = 0; i < arr; i++){
  23. result += personArray[i].toString();
  24. }
  25. return result;
  26. }
  27. public String forEachLoop() {
  28. String result = "";
  29. int arr = personArray.length;
  30. int currentPerson;
  31. for(Person people : personArray ){
  32. result += people.toString();
  33. }
  34. return result;
  35. }
  36. public Person[] getPersonArray() {
  37. return personArray;
  38. }
  39. }