In java, the following could work:
int xpathCount= driver.findElements(By.xpath("//div[@id='billingProfiles']/div[@class='cardContainer']")).size();
OR,
List<WebElement> xpath = driver.findElements(By.xpath("//div[@id='billingProfiles']/div[@class='cardContainer']"));
int xpathCount = xpath.size();
System.out.println("Total xpath: " + xpathCount);
For counting the total links in a page:
Way1:
List<WebElement> totalLinks = driver.findElements(By.tagName("a"));
int totalLinkSize = totalLinks.size();
System.out.println("Total Links by Way1 : " + totalLinkSize);
Way 2:
int totalLinkSize2 = driver.findElements(By.xpath("//a")).size();
System.out.println("Total Links by Way2 : " + totalLinkSize2);