We help IT Professionals succeed at work.
Get Started

Java arrayList

lostinspace9 asked
Last Modified: 2013-11-23
I want to be able to loop through my arraylist and determine which class it came from. I want to use that value for things further.

public class test extends JFrame{
    int [] people ;

    public test(){
	  Person [] people = new Person[4];
	  float grades[] = {90,90,91,92,92,93,93,94,94,95,96,96,95,95,95};
          ArrayList<Person> list = new ArrayList<Person>(4);
	  list.add(new Teacher("Teacher ", "One", 420));
	  list.add(new Student("Student ", "One", 11111, grades));
          list.add(new Teacher("Teacher ", "Two", 421));
	  list.add(new Student("Student ", "Two", 22222, grades));
          setLayout(new GridLayout(4, 2, 5, 5));
          for (int i=0; i< list.size(); ++i){
              add(new JTextField("" + list.get(i)), BorderLayout.WEST);

      public static void main(String[] args){
      test frame = new test(); 
      frame.setSize(400, 400);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //allow x to exit

Open in new window

Watch Question
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE