0

I have an Array of objects.

Filter[] filter = [{a:1,b:2},{c,3,d:4}]

I want to take out specific object suppose {a:1,b:2} to other object then store in rsFilter = {a:1,b:2} and remove {a:1,b:2} from array

I tried hard. I am not able to get proper logic.

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
prashanth
  • 85
  • 1
  • 3
  • 14
  • Use an `ArrayList` instead of array. It makes things simpler. – Codebender Jul 16 '15 at 08:28
  • 3
    This doesn't look like Java... – Gyro Gearless Jul 16 '15 at 08:29
  • can you share some code you have tried please .... – vidriduch Jul 16 '15 at 08:30
  • Hi, I tried using the below: List list = Arrays.asList(filter); Filter rateSheetFilter = list.remove(0); (currently it is index is 0,i will update it with correct index once it works) Filter[] ar = new Filter[2]; ar[0]=list.toArray(); (what if i have only 1 object and it is removed from my logic. that time will the list.toArry will work?) ar[1]=rateSheetFilter; return ar; I have a doubt if – prashanth Jul 16 '15 at 08:32
  • 1
    @prashanth, please put that information by editing the question. Also, when using `Arrays.asList()` you get a **fixed sized list** which means you cannot add or remove items from it. – Codebender Jul 16 '15 at 08:36

1 Answers1

0

use ArrayList for the same pupose.

List<Filter> l=new ArrayList<Filter>()

now create the objects of your Filter. add like l.add() remove like l.remove()

also see: how to use an array list?

Community
  • 1
  • 1
Piyush Mittal
  • 1,860
  • 1
  • 21
  • 39