how can I pass the Reference of an arraylist to an array?
I have an Arraylist but the method constraints that I should return an array and I should return an array with the same reference as the one given to me in the signature of the method, and I can not simply not use The ArrayList because that would require a lot of changes in the code. so is there a quick way to do it??
public Skill[] getSkills() {
if (skills.size() == 0) {
return null;
}
Skill[] result = new Skill[skills.size()];
result = skills.toArray(result);
return result;
}
public void setSkills(Skill[] skills) {
if (skills.length != 0) {
for (int i = 0; i < skills.length; i++) {
this.skills.add(i, skills[i]);
}
}
}
the Junit test is:
@Test(timeout = 1000)
public void testGetSkills() {
instance.setSkills(skills);
assertSame("The returned skill array should be the same", instance.getSkills(), skills);
}