Get all the window handles then iterate through them, switching web driver to the new handle, then calling the close method. Obviously, skip this for the original handle, then switch back to the remaining handle.
below is the code;
String originalHandle = driver.getWindowHandle();
//Do something to open new tabs
for(String handle : driver.getWindowHandles()) {
if (!handle.equals(originalHandle)) {
driver.switchTo().window(handle);
driver.close();
}
}
driver.switchTo().window(originalHandle);