How to filter an array in Java?

后端 未结 7 996
小蘑菇
小蘑菇 2020-12-10 02:01

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         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 02:51

    EDIT: saw that ArrayList is not in J2ME, but based on documentation, it does have a Vector. If that Vector class is different than J2SE Vector (as this documentation indicates), then perhaps the following code would work:

    Vector carList = new Vector();
    for(int i = 0; i 4)
             carList.addElement(cars[i]);
        }
    }
    Car[] carArray = new Car[carList.size()];
    carList.copyInto(carArray);
    

提交回复
热议问题