title: is there a way to access an object within an object?
body: <p>I'm practicing java by building a simple directory. I have 4 Classes. These are:</p>
  
  <ol>
  <li><p>Person</p></li>
  <li><p>Address</p></li>
  <li><p>Contact</p></li>
  <li><p>testClass</p></li>
  </ol>
  
  <p>I have already finished creating this system and it works the way I want it. I did this by making 3 different arrays for the Person, Address and Contact. To link the Person, Address and Contact together I place them on there respective array with the same index number. (Not literally linking them together, just a way to know which address or contact to access when editing a person).</p>
  
  <p>But now, I want to optimize it. I want to create a single HashMap to hold a person with the address and contacts within it. Please see my code below for more information.</p>
  
  <p>Person.class</p>
  
  <pre><code>public class Person {
  private long Id;
  private firtName;
  private Address address;
  private Contact contact;
  
  //some setter and getter methods
  
  public Person(Address address, Contact contact) {
  this.address = address;
  this.contact = contact;
  }
  }
  </code></pre>
  
  <p>Address.class</p>
  
  <pre><code>public class Address {
  
  private String street;
  private String city;
  private String province;
  
  
  //some setter and getter methods
  }
  </code></pre>
  
  <p>Contact.class</p>
  
  <pre><code>public class Contact {
  
  private long Phone;
  private String Email;
  
  //some setter and getter methods
  }
  </code></pre>
  
  <p>testClass.class</p>
  
  <pre><code>public class testClass {
  
  public static void main(String[] args) {
  HashMap&lt;Integer, Person&gt; person = new HashMap&lt;Integer, Person&gt;();
  
  person.put(1, new Person(new Address(), new Contact)));
  person.get(1).setStreet("place");
  
  }
  
  }
  </code></pre>
  
  <p>My question is, on this line of code in the testClass</p>
  
  <pre><code>person.get(1).setStreet("place");
  </code></pre>
  
  <p>is there a way to directly access/edit the person's address or contact without creating a separate array or method?</p>