java - Grouping values by a common attribute in a matrix -
i'm having trouble in transforming 2-d matrix 2d array/list/vector based on common value of original matrix.
for example have ordered 2d_array of string(the code quite big) shown bellow.
string [][] 2d_array = { {1922, abc}, {1922, xpt}, {1954,abc}, {2001, sss}, {2001, asd}}; // array has "n" row i transform/create following "output".
new_array = {{1922, abc, xpt}, {1954, abc}, {2001, sss, asd}}; in new array not matter how long number of columns be, long in same row accordingly "number"/date/index/etc.
try:
map<string, set<string>> res = arrays.stream(2d_array) .collect(groupingby(a -> a[0], mapping(a -> a[1], toset()))); you can convert map desired array if find array more convenient.
Comments
Post a Comment