title: Dynamic Programming: Bits Array Java
body: <p>I need to solve a <code>Dynamic Programming</code> problem for which I need to create a <code>N*N</code> size matrix in the memory. If I do create a matrix of <code>byte[][]</code> with size <code>N = 100000;</code> then it throws <code>java.lang.OutOfMemoryError: Java heap space</code> error.</p>
  
  <p>In this matrix I will store either 0 or 1 at particular <code>ith</code> and <code>jth</code> index. So my use is limited to a bit only and I need a way so that I can just use only 1 bit size per matrix cell rather than over flooding memory keeping 8 bits in a cell where the need is only for 1 bit.</p>
  
  <p>How can I achieve this?</p>
  
  <p>Please take a note that my concern is not increasing heap of JVM, I am just searching for a way to optimally achieve the solution of a Dynamic Problem.</p>