Java code to check checkbox

public WebElement clickCheckbox (WebDriver driver, WebDriverWait wait, String xpath)
{
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
Actions actions = new Actions(driver);
WebElement element = null;
if (!driver.findElement(By.xpath(xpath)).isSelected())
{
element = driver.findElement(By.xpath(xpath));
actions.moveToElement(element).click().build().perform();
}
return element;
}

Web element

Java code to check checkbox by index

public void clickCheckboxByIndex (WebDriver driver, WebDriverWait wait, int index)
{
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[2]/div[2]/table/tbody/tr[" + index + "]/td/input")));
Actions actions = new Actions(driver);
if(!driver.findElement(By.xpath("/html/body/div[2]/div[2]/table/tbody/tr[" + index + "]/td/input")).isSelected())
{
WebElement element = driver.findElement(By.xpath("/html/body/div[2]/div[2]/table/tbody/tr[" + index + "]/td/input"));
actions.moveToElement(element).click().build().perform();
}
}

A list of web elements