{"id":641,"date":"2021-07-13T23:34:34","date_gmt":"2021-07-13T23:34:34","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=641"},"modified":"2021-09-11T11:04:58","modified_gmt":"2021-09-11T11:04:58","slug":"how-to-count-number-of-characters-in-a-string","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/","title":{"rendered":"How to count number of characters in a string ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"how-to-count-number-of-characters-in-a-string\" class=\"color-pink\">How to count number of characters in a string ?<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li>To count the amount of \u2018x\u2019 characters that are in a string, and print out the number using java program.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"CodeContent\"><\/div>\n<div class=\"Output\">\n<div class=\"hddn\">\n<figure class=\"highlight\"><div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-java code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-java code-embed-code\">class Wikitechy<br\/>{ <br\/>    \/\/ Method that return count of the given <br\/>    \/\/ character in the string <br\/>    public static int count(String s, char c) <br\/>    { <br\/>        int res = 0; <br\/>  <br\/>        for (int i=0; i<s.length(); i++) <br\/>        { <br\/>            \/\/ checking character in string <br\/>            if (s.charAt(i) == c) <br\/>            res++; <br\/>        }  <br\/>        return res; <br\/>    } <br\/>      <br\/>    \/\/ Driver method <br\/>    public static void main(String args[]) <br\/>    { <br\/>        String str= &quot;Welcome to Wikitechy&quot;; <br\/>        char c = &#039;W&#039;; <br\/>        System.out.println(count(str, c)); <br\/>    } <br\/>} <\/code><\/pre> <\/div>\n<h3 id=\"output\">Output<\/h3>\n<p>2<\/figure>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : To count the amount of &#8216;x&#8217; characters that are in a string&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4004],"tags":[195,491,360,203,199,214,4239,4236,4241,198,363,209,4244,4246,4248,4250,4252,4215,4240,15937,205,4243,2936,222,4253,4251,196,212,213,4217,4249,286,207,366,4247,204,217,282,4023,483,206,200,197,280,364,968,4237],"class_list":["post-641","post","type-post","status-publish","format-standard","hentry","category-java","tag-accenture-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-atos-interview-questions-and-answers","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-char-to-string","tag-character-count","tag-check-string-length","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-collabera-technologies-interview-questions-and-answers","tag-count-characters-in-string","tag-count-characters-in-string-java","tag-count-number-of-characters-in-a-string","tag-count-number-of-characters-in-a-string-in-java","tag-count-occurrences-of-character-in-string-java-using-hashmap","tag-count-repeated-characters-in-string-using-java","tag-count-words-in-string","tag-dark-horse-digital-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-excel-count-characters-in-string","tag-fis-global-business-solutions-india-pvt-ltd-interview-questions-and-answers","tag-flipkart-interview-questions-and-answers","tag-how-to-count-characters-in-string-array-in-java","tag-how-to-count-the-number-of-occurrences-of-a-character-in-a-string-in-java","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-infosys-technologies-interview-questions-and-answers","tag-java-program-to-count-number-of-alphabets-in-a-string","tag-java-program-to-count-number-of-characters-in-a-string","tag-lt-infotech-interview-questions-and-answers","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-number-of-characters-in-a-string","tag-oracle-corporation-interview-questions-and-answers","tag-peoplestrong-interview-questions-and-answers","tag-persistent-systems-interview-questions-and-answers","tag-rbs-india-de-interview-questions-and-answers","tag-reliance-industries-ltd-interview-questions-and-answers","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-unitedhealth-group-interview-questions-and-answers","tag-virtusa-consulting-services-pvt-ltd-interview-questions-and-answers","tag-wells-fargo-interview-questions-and-answers","tag-wipro-infotech-interview-questions-and-answers","tag-word-counter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to count number of characters in a string ? - Java<\/title>\n<meta name=\"description\" content=\"How to count number of characters in a string ? - To count the amount of &#039;x&#039; characters that are in a string, and print out the number using java program.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to count number of characters in a string ? - Java\" \/>\n<meta property=\"og:description\" content=\"How to count number of characters in a string ? - To count the amount of &#039;x&#039; characters that are in a string, and print out the number using java program.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T23:34:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-11T11:04:58+00:00\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/\"},\"author\":{\"name\":\"Editor\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"headline\":\"How to count number of characters in a string ?\",\"datePublished\":\"2021-07-13T23:34:34+00:00\",\"dateModified\":\"2021-09-11T11:04:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/\"},\"wordCount\":173,\"commentCount\":0,\"keywords\":[\"Accenture interview questions and answers\",\"Applied Materials interview questions and answers\",\"Atos interview questions and answers\",\"Capgemini interview questions and answers\",\"CASTING NETWORKS INDIA PVT LIMITED interview questions and answers\",\"CGI Group Inc interview questions and answers\",\"char to string\",\"character count\",\"check string length\",\"Chetu interview questions and answers\",\"Ciena Corporation interview questions and answers\",\"Collabera Technologies interview questions and answers\",\"count characters in string\",\"count characters in string java\",\"count number of characters in a string\",\"count number of characters in a string in java\",\"count occurrences of character in string java using hashmap\",\"count repeated characters in string using java\",\"count words in string\",\"dark horse digital interview questions and answers\",\"Dell International Services India Pvt Ltd interview questions and answers\",\"excel count characters in string\",\"FIS Global Business Solutions India Pvt Ltd interview questions and answers\",\"Flipkart interview questions and answers\",\"how to count characters in string array in java\",\"how to count the number of occurrences of a character in a string in java\",\"IBM interview questions and answers\",\"Indecomm Global Services interview questions and answers\",\"Infosys Technologies interview questions and answers\",\"java program to count number of alphabets in a string\",\"java program to count number of characters in a string\",\"L&amp;T Infotech interview questions and answers\",\"Mphasis interview questions and answers\",\"NetApp interview questions and answers\",\"number of characters in a string\",\"Oracle Corporation interview questions and answers\",\"PeopleStrong interview questions and answers\",\"Persistent Systems interview questions and answers\",\"RBS India De interview questions and answers\",\"Reliance Industries Ltd interview questions and answers\",\"SAP Labs India Pvt Ltd interview questions and answers\",\"Tech Mahindra interview questions and answers\",\"UnitedHealth Group interview questions and answers\",\"Virtusa Consulting Services Pvt Ltd interview questions and answers\",\"Wells Fargo interview questions and answers\",\"Wipro Infotech interview questions and answers\",\"word counter\"],\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/\",\"name\":\"How to count number of characters in a string ? - Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"datePublished\":\"2021-07-13T23:34:34+00:00\",\"dateModified\":\"2021-09-11T11:04:58+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"How to count number of characters in a string ? - To count the amount of 'x' characters that are in a string, and print out the number using java program.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/java\\\/how-to-count-number-of-characters-in-a-string\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/author\\\/editor\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to count number of characters in a string ? - Java","description":"How to count number of characters in a string ? - To count the amount of 'x' characters that are in a string, and print out the number using java program.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/","og_locale":"en_US","og_type":"article","og_title":"How to count number of characters in a string ? - Java","og_description":"How to count number of characters in a string ? - To count the amount of 'x' characters that are in a string, and print out the number using java program.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/","og_site_name":"Wikitechy","article_published_time":"2021-07-13T23:34:34+00:00","article_modified_time":"2021-09-11T11:04:58+00:00","author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/"},"author":{"name":"Editor","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"headline":"How to count number of characters in a string ?","datePublished":"2021-07-13T23:34:34+00:00","dateModified":"2021-09-11T11:04:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/"},"wordCount":173,"commentCount":0,"keywords":["Accenture interview questions and answers","Applied Materials interview questions and answers","Atos interview questions and answers","Capgemini interview questions and answers","CASTING NETWORKS INDIA PVT LIMITED interview questions and answers","CGI Group Inc interview questions and answers","char to string","character count","check string length","Chetu interview questions and answers","Ciena Corporation interview questions and answers","Collabera Technologies interview questions and answers","count characters in string","count characters in string java","count number of characters in a string","count number of characters in a string in java","count occurrences of character in string java using hashmap","count repeated characters in string using java","count words in string","dark horse digital interview questions and answers","Dell International Services India Pvt Ltd interview questions and answers","excel count characters in string","FIS Global Business Solutions India Pvt Ltd interview questions and answers","Flipkart interview questions and answers","how to count characters in string array in java","how to count the number of occurrences of a character in a string in java","IBM interview questions and answers","Indecomm Global Services interview questions and answers","Infosys Technologies interview questions and answers","java program to count number of alphabets in a string","java program to count number of characters in a string","L&amp;T Infotech interview questions and answers","Mphasis interview questions and answers","NetApp interview questions and answers","number of characters in a string","Oracle Corporation interview questions and answers","PeopleStrong interview questions and answers","Persistent Systems interview questions and answers","RBS India De interview questions and answers","Reliance Industries Ltd interview questions and answers","SAP Labs India Pvt Ltd interview questions and answers","Tech Mahindra interview questions and answers","UnitedHealth Group interview questions and answers","Virtusa Consulting Services Pvt Ltd interview questions and answers","Wells Fargo interview questions and answers","Wipro Infotech interview questions and answers","word counter"],"articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/","name":"How to count number of characters in a string ? - Java","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"datePublished":"2021-07-13T23:34:34+00:00","dateModified":"2021-09-11T11:04:58+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"How to count number of characters in a string ? - To count the amount of 'x' characters that are in a string, and print out the number using java program.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/java\/how-to-count-number-of-characters-in-a-string\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":660,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/641\/revisions\/660"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}