Skip to content

Instantly share code, notes, and snippets.

@claytantor
Created November 14, 2015 13:46
Show Gist options
  • Save claytantor/55536c8f18259f36f0f4 to your computer and use it in GitHub Desktop.
Save claytantor/55536c8f18259f36f0f4 to your computer and use it in GitHub Desktop.
Creating a guava table using column names
Table<Integer, String, Object> table = HashBasedTable.create();
String[] columnNamesArray = (String[])columnNames.toArray(new String[columnNames.size()]);
List<List>[] rows = (List<List>[])data.toArray(new List[data.size()]);
for(int i = 0; i < rows.length; i++){
Object[] objectArray = rows[i].toArray();
for (int j = 0; j < objectArray.length; j++) {
if(j==0){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(objectArray[j].toString());
table.put(i, columnNamesArray[j], date);
} else {
table.put(i, columnNamesArray[j] , objectArray[j]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment