aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Size of Char Array." Watch "Size of Char Array." New topic
Author

Size of Char Array.

Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 95
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: 10376
    
    8

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
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

3.

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: 14150
    
  18

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
Rancher

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Size of Char Array.