
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count 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
Advertisements