Click and visit each and every link in a website using selenium

package SeleniumLearn.Com;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;

public class ClickandVisit{
     public WebDriver driver;

@Test
  public void ClickandVisitAllLinks() {
  driver.get("http://www.google.com");
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  List<String> hrefs = new ArrayList<String>();
  List<WebElement> anchors = driver.findElements(By.tagName("a"));
  for ( WebElement anchor : anchors ) 
{
  hrefs.add(anchor.getAttribute("href"));
  }
  for ( String href : hrefs ) 
{
  driver.get(href);           
  }
  }

@BeforeTest
  public void beforeTest() {
      
//System.setProperty("webdriver.gecko.driver","path of geckodriver.exe"); // Selenium 3 - Launching firefox browser using Geckodriver 
//WebDriver driver = new FirefoxDriver();

                          

//System.setProperty("webdriver.chrome.driver","Path of chromedriver.exe"); 
//driver=new ChromeDriver();

  }

@AfterTest
  public void afterTest() {
  }
}