File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Size of Char Array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Size of Char Array." Watch "Size of Char Array." New topic

Size of Char Array.

Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 82
String str = new String("abc");

What is the size of the character array that got created for the same.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990

So what do you think?
Did you check the API docs for any methods which will help you solve this?

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825


There is a method provided by String class that you can use to convert string to a character array. Following that you can retrieve the length of the array. Check API to find it.

The quieter you are, the more you are able to hear.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13872

Santosh Kumar Nayak wrote:String str = new String("abc");

Note that you should never write code like this. Just write:

String str = "abc";

It is never necessary to explicitly create a new String object if you're initializing it with a literal, such as "abc".

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ivan Jozsef Balazs

Joined: May 22, 2012
Posts: 865
The API description (a valuable resource worth studying for every developer) mentions this method of String:

I agree. Here's the link:
subject: Size of Char Array.
Similar Threads
Args[] array in main method
How can I specify size of a String?
fetch in integer variable
int[] = null; help
how to calculate number of arguments in a function