title: return array from method to get objects from a hashmap - java
body: <p>I have a hashmap containing objects created via a constructor. 
  These objects are in the hashmap</p>
  
  <p>I have a function that compares two arrays. The one array has been manually created, but the second array is created via a method. I need only the values from the hashmap. </p>
  
  <pre><code>String[] checkOne= { "1.2:3,4:Brown", "1.1:5,4:Green" };
  
  Map&lt;String,RoundBrick&gt; hashMap = new HashMap&lt;String, RoundBrick&gt;();
  
  public void addBrick(RoundBrick roundBrick){
      hashMap.put(roundBrick.getRef, roundBrick)
  }
  
  checkBrick(getBricks(), one){
  ...
  }
  
  public static boolean checkBrick(Brick[] brick, String[] checkOne){
  ...
  }    
  </code></pre>
  
  <p>Where I am stuck is with this method...  </p>
  
  <pre><code>public Brick[] getBricks(){
  </code></pre>
  
  <p>How do I convert the objects from the hashmap to an array, so I can compare the contents of the two arrays?
  I can go... </p>
  
  <pre><code>public Brick[] getBricks() {   
  Brick[] bricks = {hashmap.value().toArray()};   
  return bricks;    
  }
  </code></pre>
  
  <p>But this give error saying cannot convert from Object[] to Brick</p>
  
  <ul>
  <li>if I take .toArray() out, I get a "cannot convert from Collection&lt; RoundBrick > to Brick"</li>
  <li>if I change .toArray() to .toString(), I get a "cannot convert from String to Brick"  </li>
  </ul>
  
  <p>If I change the method to the following... </p>
  
  <pre><code>public Brick[] getBricks() {
      String a = Arrays.toString(hashmap.values().toArray());
      return a;
  }
  </code></pre>
  
  <p>The error I get on "a" is "cannot convert from String to Brick[]"</p>
  
  <p>And when adding the line below, it prints out the array. </p>
  
  <pre><code>System.out.print(hashmap.values());
  
  [1.2:3,4:Brown, 1.1:5,4:Green]
  </code></pre>
  
  <p>can anyone point me into the right direction?</p>