Created
November 14, 2015 13:46
-
-
Save claytantor/55536c8f18259f36f0f4 to your computer and use it in GitHub Desktop.
Creating a guava table using column names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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