How can I filter an array in Java?
I have an array of objects, for example cars:
Class:
public class Car{ public int doors; public Ca
You can use System.arrayCopy():
System.arrayCopy()
Car[] cars = ... int length = cars.length < 4 ? cars.length() : 4; Car filter = new Car[4]; System.arrayCopy(cars, 0, filter, 0, length);
UPDATE: System.arrayCopy is available in Java ME API, unlike Vector.subList(). Thanks for the correction.
System.arrayCopy