I have a hashmap containing objects created via a constructor. These objects are in the hashmap
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.
String[] checkOne= { "1.2:3,4:Brown", "1.1:5,4:Green" };
Map<String,RoundBrick> hashMap = new HashMap<String, RoundBrick>();
public void addBrick(RoundBrick roundBrick){
hashMap.put(roundBrick.getRef, roundBrick)
}
checkBrick(getBricks(), one){
...
}
public static boolean checkBrick(Brick[] brick, String[] checkOne){
...
}
Where I am stuck is with this method...
public Brick[] getBricks(){
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...
public Brick[] getBricks() {
Brick[] bricks = {hashmap.value().toArray()};
return bricks;
}
But this give error saying cannot convert from Object[] to Brick
- if I take .toArray() out, I get a "cannot convert from Collection< RoundBrick > to Brick"
- if I change .toArray() to .toString(), I get a "cannot convert from String to Brick"
If I change the method to the following...
public Brick[] getBricks() {
String a = Arrays.toString(hashmap.values().toArray());
return a;
}
The error I get on "a" is "cannot convert from String to Brick[]"
And when adding the line below, it prints out the array.
System.out.print(hashmap.values());
[1.2:3,4:Brown, 1.1:5,4:Green]
can anyone point me into the right direction?