-2

I have lots of boolean arrays and i want to keep them in an array list so that i can access them through this array list .

public static boolean one[] = { false, false, false,false,false,false,false,false,false,false,false
};
public static boolean two[] = { false, false, false,false,false,false,false,false,false,false,false
};

ArrayList myImage; // for normal object'

when i try ArrayList myBooleans; // its not working . and so on

I want an array list that will hold all this arrays.

Any help will be appreciated.

Suman Palikhe
  • 357
  • 1
  • 4
  • 16

1 Answers1

0

Use a sparse matrix your storage seems mostly same value.

You can create list of Boolean Arrays, but cant do it for primitive boolean. That lot of memory wastage and best way is to have Array or sparse array[array having only true value locations]

  • I change it from primitive to Boolean type, int to Integer and checked the size of the file it's not much difference – Suman Palikhe Jul 09 '15 at 14:36
  • Sparse Mtx is different than change of primitive to object. For example if you have an array of 100 int/Integer, and 99 values are 0 and only one value is say 5, then in this example its not good to store it as array of 100 int, instead you can store it as array of non zero element values and position like [5][89][76], a single value representing array of 100 integers. –  Jul 13 '15 at 07:14
  • Thanks for that. But I don't understand how [5][89][76] represents the whole array. – Suman Palikhe Jul 14 '15 at 08:16
  • Its simple, suppose we need to store an array of 100 int values in which 99% time value will be 0, we can store only non zero element value and its position in imaginary array. This is only applicable when most of the values are same ( e.g. 0, true/false) –  Jul 14 '15 at 13:05