1

I am wondering if there is a way to use a loop to display class information.

For example, if I have multiple instance created like,

Specimen a = new Specimen("1", "2", "3");
Specimen b = new Specimen("4", "5", "6");

and a toString method which would display my information in the desired way; is there any possible way to use a loop or while to print a.toString() and b.toString() and so on (c,d,e,f,g, etc) without having to continuously type a.toString(), b.toString, etc.

This is currently what my main method looks like

    public static void main(String[]args){
        Specimen SF11 = new Specimen("SF11", "Starfish", 10, 20 );
        System.out.println(SF11.toString());
        Specimen SU12 = new Specimen("SU12", "Sea Urchin", 12, 25);
        System.out.println(SU12.toString());
        SF11.setsCount(16); SF11.setsName("Blue Starfish"); SF11.setsTank(22);
        System.out.print(SF11.toString() + "\n" + SU12.toString());
    }
}
asdfghjklm
  • 643
  • 2
  • 7
  • 18
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/129326/discussion-on-question-by-kylian-murphy-can-you-display-all-information-from-a-c). – Bhargav Rao Nov 29 '16 at 07:52

0 Answers0