How to count character in java string

Code to get the character in String. We can use length function in String class.

package com.string;

/*
 * Here we will learn how to count the number of character in String
 */
public class CountCharInString {

	public static void main(String args[]) {
		String str = "Hello";

		System.out
				.println("Length of the String or Number of character in String : "
						+ str.length());

	}
}

 

By | 2012-07-01T08:03:47+00:00 July 1st, 2012|Code Base|0 Comments

About the Author:

Leave A Comment