4. Implement the method copyArray. Use indexes to implement this method. • public static Employee[] copyArray(Employee[] array).
时间: 2024-05-15 16:17:34 浏览: 103
Sure, here's the implementation for the `copyArray` method that takes an array of `Employee` objects and returns a new array with the same elements:
```java
public static Employee[] copyArray(Employee[] array) {
Employee[] newArray = new Employee[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = array[i];
}
return newArray;
}
```
In this implementation, we create a new array `newArray` with the same length as the input array `array`. Then, we iterate over the indexes of `array`, copying the element at each index to the corresponding index in `newArray`. Finally, we return `newArray`.
阅读全文