Assistance with Match-3 Style Game Logic

Hi guys,

I would like to build a “connect the dots” style game.

I already know how to fill in the grid for the game and i know how to remove the objects when the user selects a pair.

The problem is, i am not sure how to fill in spaces when objects are removed.

For example, if 2 items are removed from row 1 and 1 item is removed from row 2. what would be the algorithm to drop the items in row 2 down to slots, and the items in row 1 down 1 position above where the item was removed.

I hope i exlained my question well. For this game i will be using Libgdx(which is java) so any java pseudocode will be GREAT. I will also be using sprites of libgdx and tween engine to move objects.

Thanks so much guys, hope i can find the help i need.