0

I wish to try to make an array reference a class but can not think of a way to do this. I have my main class, client and another called organisation.

Im basically making a small database where the user is able to add an organisation and also edit the info in the organisation. Info including, ID#, name, address, ect

I d like to know how i can get an array to basically store new organisation class's so that when i want to add an organisation it runs a new organisation class and stores that version of the class, in the array.

6
  • Is Class<?>[] what you're looking for? Commented Oct 22, 2012 at 6:57
  • What is this? Please Explain :D Commented Oct 22, 2012 at 6:58
  • Class<?> is a reflection type for a Java class. The <?> means "any class" using the generic type syntax. Commented Oct 22, 2012 at 6:59
  • 1
    Is it not appropriate to just have an array of organisations: Organisation[]? Commented Oct 22, 2012 at 7:01
  • Of course, you should not be storing Classes in a database. Commented Oct 22, 2012 at 7:01

2 Answers 2

2

You may be best using a List, unless you can be sure of the maximum number of organisations that can be associated with a client. The size of an array is fixed at the point it is created, which may not be appropriate for your use case.

For example:

public class Client {
  private final List<Organisation> organisations = new ArrayList<Organisation>();

  void addOrganisation() {
    // dummy/example method
    organisations.add(new Organisation("Foo", new Address("blah")));
  }
}

public class Organisation {
  private final String name;
  private final Address address;

  public Organisation(String name, Address address) {
    this.name = name;
    this.address = address;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

ArrayList<Organisation>

is the best option I think. read the documentation to get familiar with it. it's quiet handy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.