title: Write more than 25 items using BatchWriteItemEnhancedRequest Dynamodb JAVA SDK 2
body: <p>I have an List items to be inserted into the DynamoDb collection. The size of the list may vary from 100 to 10k. I looking for an optimised way to Batch Write all the items using the BatchWriteItemEnhancedRequest (JAVA SDK2). What is the best way to add the items into the WriteBatch builder and then write the request using BatchWriteItemEnhancedRequest?</p>
  <p>My Current Code:</p>
  <pre><code>   WriteBatch.Builder&lt;T&gt; builder = BatchWriteItemEnhancedRequest.builder().writeBatches(builder.build()).build();
  
     items.forEach(item -&gt; { builder.addPutItem(item); });
  
     BatchWriteItemEnhancedRequest bwr = BatchWriteItemEnhancedRequest.builder().writeBatches(builder.build()).build()
  
     BatchWriteResult batchWriteResult =
              DynamoDB.enhancedClient().batchWriteItem(getBatchWriteItemEnhancedRequest(builder));
  
      do {
          // Check for unprocessed keys which could happen if you exceed
          // provisioned throughput
          List&lt;T&gt; unprocessedItems = batchWriteResult.unprocessedPutItemsForTable(getTable());
  
          if (unprocessedItems.size() != 0) {
              unprocessedItems.forEach(unprocessedItem -&gt; {
                  builder.addPutItem(unprocessedItem);
              });
              batchWriteResult = DynamoDB.enhancedClient().batchWriteItem(getBatchWriteItemEnhancedRequest(builder));
          }
  
      } while (batchWriteResult.unprocessedPutItemsForTable(getTable()).size() &gt; 0);
  </code></pre>
  <p>Looking for a batching logic and a more better way to execute the BatchWriteItemEnhancedRequest.</p>