• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of Char Array.

 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
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?
 
Kemal Sokolovic
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
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".
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • 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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic