- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to count the number characters in a Java string?
Declare an integer, initialize it with 0, in for loop increment it for each character.
Example
public class Sample { public static void main(String args[]) { String str = new String("Hi welcome to Tutorialspoint"); int count = 0; for(int i = 0; i<str.length(); i++) { count++; } System.out.println("Number characters in the given string (including spaces) "+count); } }
Output
Number characters in the given string (including spaces) 28
- Related Articles
- Count the Number of matching characters in a pair of Java string
- How to count the number of repeated characters in a Golang String?
- Python Program to Count Number of Lowercase Characters in a String
- How to count the number of characters (including spaces) in a text file using Java?
- Count Number of Lowercase Characters in a String in Python Program
- Count the Number of matching characters in a pair of string in Python
- Java Program to count the number of words in a String
- Java program to count upper and lower case characters in a given string
- Program to count number of distinct characters of every substring of a string in Python
- How to replace characters on String in Java?
- C++ Program to count number of characters to be removed to get good string
- How to count the number of words in a string in R?
- How to implement a program to count the number in Java?
- Java Program to Find the Duplicate Characters in a String
- How to Count the Number of Vowels in a string using Python?

Advertisements