Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

size of string

 
Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to send 1K bytes string data through the socket. Just wondering, for a string as "abc", is its size 6 bytes? I know one char is 16 bits but I would like to confirm it.
Thanks
Chris
 
Jyothi Lature
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,
You are right. In java, charis 2 bytes size. So String "abc" is of size 6bytes.
Have fun,
Jyothi
 
Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. May I ask what exactly is happening if I send a string as "123" or ")|("? I think they are 6 bytes, too, but they are not chars, aren't they?
Chris
 
Jyothi Lature
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,
In java,
String str = "abc";
is equivalent to:
char data[] = {'a', 'b', 'c'};
So, the size of this string variable will be 6 bytes.
Similarly, String "123" or ")|(" is again an array of chars whose size will be 6 bytes.
Hope its clear.
Happy coding.
-Jyothi
 
Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I was dumb .
thanks a have a good weekend
Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic