• Post Reply Bookmark Topic Watch Topic
  • New Topic

Size of Char Array.  RSS feed

 
Ranch Hand
Posts: 227
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str = new String("abc");

What is the size of the character array that got created for the same.
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what do you think?
Did you check the API docs for any methods which will help you solve this?
 
Bartender
Posts: 825
5
Java Python Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Sheriff
Posts: 16082
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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".
 
Rancher
Posts: 1016
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API description (a valuable resource worth studying for every developer) mentions this method of String:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!