title: Arraylist of Arrays, How to make last array size somehow different from other arrays in the list
body: <p><strong>Explanation of what i am trying to acheive:</strong></p>
  
  <p>I am given a  file and i have to read data from the file and create blocks of sizes 1 kb. For example : If the file size is 5.8 kb then i will have 5 blocks of 1 kb each and 1 last block of 0.8 kb. After having these in the block i have to do SHA 256 encoding from the last block and append it to the second last block, after that i have to apply the encoding to the second last block and append it to the third last and so on. </p>
  
  <p><strong>Problem</strong></p>
  
  <p>If i am given multiple of 1024 byte file size then my code works well. But if my last block size is not 1024 then the code doesnot work as intended.</p>
  
  <p>The way i am doing this now is :</p>
  
  <pre><code>BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
  int sizeOfBlock = 1024;
  int sizeOfHash = 256;
  
  MessageDigest md;
  md = MessageDigest.getInstance("SHA-256");
  
  byte[] block = new byte[sizeOfBlock];
  
  List &lt;byte []&gt; blockList = new ArrayList &lt;byte []&gt;();
  
  int tmp = 0;
  while ((tmp = bis.read(block)) &gt; 0) {
      System.out.println(tmp);
      blockList.add(block);           
  }       
  
  for (int j = blockList.size()-1; j &gt; 0;){
      System.out.println(blockList.get(j).length); // for the first iteration it shouldnt be 1024 if the file size is not a multiple of 1024
      md.update(blockList.get(j--));
      byte[] hash = md.digest();
      byte[] appendBlock = new byte[blockList.get(j).length + hash.length];
  
      System.arraycopy(blockList.get(j), 0, appendBlock, 0, blockList.get(j).length);
      System.arraycopy(md.digest(), 0, appendBlock, blockList.get(j).length, hash.length);
      blockList.set(j, appendBlock);      
  }
  
  System.out.println(blockList.get(0).length);
  md.update(blockList.get(0));
  byte[] hash = md.digest();
  
  String result = bytesToHex(hash); // converting function from byte to hex
  System.out.println(result);
  </code></pre>