public class MainActivity extends AppCompatActivity { public static class Shop { public int id; public String name; public List coordinates = new ArrayList<>(); @Override public String toString() { String str = id + " (" + name + ") [ "; for (Coordinate coordinate : coordinates) { str += (coordinate.toString() + " "); } str += "]"; return str; } } public static class Coordinate { public String latitude; public String longitude; public Coordinate(String latitude, String longitude) { this.latitude = latitude; this.longitude = longitude; } @Override public String toString() { return "{" + latitude + ", " + longitude + "}"; } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] cursor1row = {"1", "Foo", "lat1-1", "long1-1"}; String[] cursor2row = {"1", "Foo", "lat1-2", "long1-2"}; String[] cursor3row = {"2", "Bar", "lat2-1", "long2-1"}; String[] cursor4row = {"1", "Foo", "lat1-3", "long1-3"}; String[] cursor5row = {"1", "Foo", "lat1-4", "long1-4"}; String[] cursor6row = {"3", "Ping", "lat3-1", "long3-1"}; String[] cursor7row = {"2", "Bar", "lat2-2", "long2-2"}; List cursor = Arrays.asList(cursor1row, cursor2row, cursor3row, cursor4row, cursor5row, cursor6row, cursor7row); Observable.from(cursor) .groupBy(cursorRow -> cursorRow[0]) .flatMap(groups -> groups.collect(Shop::new, (shop, rows) -> { shop.id = Integer.parseInt(rows[0]); shop.name = rows[1]; shop.coordinates.add(new Coordinate(rows[2], rows[3])); })) .subscribe(shop -> Log.d("RX", shop.toString())); } }