How can I initialize an array without knowing it size?

前端 未结 4 1087
青春惊慌失措
青春惊慌失措 2021-02-07 01:55

I have a situation, where I have to apply a criteria on an input array and reuturn another array as output which will have smaller size based upon the filtering criteria.

4条回答
  •  日久生厌
    2021-02-07 02:07

    Just return any kind of list. ArrayList will be fine, its not static.

        ArrayList list = new ArrayList();
    for (yourClass item : yourArray) 
    {
       list.add(item); 
    }
    

提交回复
热议问题