title: How to populate Google Sheets via API in Java
body: <p>I have a 3 column Spreadsheet [Date, Time, Subject] that I want to populate via the Sheets API using Java.</p>
  
  <p>I understand how to read rows:</p>
  
  <pre><code>    for (List row : values)
          System.out.println(row.get(0) + row.get(1) + row.get(2));
  </code></pre>
  
  <p>But I am having trouble using their documentation to understand <strong>how to insert specific strings into specific rows and columns</strong>. I know there exists a method <code>row.set(int index, Object element)</code> but when I try to insert a new row like this:</p>
  
  <pre><code>    for (List row : values)
      {
          row.set(0, message.full_date);
          row.set(1, message.time);
          row.set(2, message.subject);
      }
  </code></pre>
  
  <p>nothing is updating in my sheets. My full code:</p>
  
  <pre><code>private static void Update_Sheets(Sheets sheets_service, GmailMessage message) throws IOException
      {
          String spreadsheetId = id;
  
          String range = "Sheet1!A1:C2";
          ValueRange response = sheets_service.spreadsheets().values()
                  .get(spreadsheetId, range)
                  .execute();
          List&lt;List&lt;Object&gt;&gt; values = response.getValues();
  
          for (List row : values)
          {
              row.set(0, message.full_date); //a string
              row.set(1, message.time);      //a string
              row.set(2, message.subject);   //a string
          }
      }
  </code></pre>