How many bytes in memory a string occupy in Java language?-VBForums
Results 1 to 4 of 4

Thread: How many bytes in memory a string occupy in Java language?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    17

    How many bytes in memory a string occupy in Java language?

    How many bytes in memory a string occupy in Java language?
    Suppose i write:
    String name="Bill Gates";
    So, how much memory it requires? Whether it can store a UNICODE character in the string. How internally it is implemented, using a 1 byte char array or 2 byte Unicode char array? I read somewhere that Java's char data type is 16 bit wide.

    Thanks!!!

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    6,513

    Re: How many bytes in memory a string occupy in Java language?

    Thread moved. The code bank forums are for your code submissions rather than questions.
    You can depend upon the Americans to do the right thing. But only after they have exhausted every other possibility - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,119

    Re: How many bytes in memory a string occupy in Java language?

    Indeed it is,
    http://docs.oracle.com/javase/tutori...datatypes.html

    char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,531

    Re: How many bytes in memory a string occupy in Java language?

    Except when it is UTF-8.

    Data extracted using a String.getBytes() call defaults to the platform default, which is ANSI on Windows ("Windows-1252") and UTF-8 on most *nix platforms. Of course you can use String.getBytes("UTF-8") to be specific and work on all platforms.

    But yes, String itself is always UTF-16... though it can vary between the LE and BE variations based on platform.

    Not understanding these platform issues is why some plinkers get frustrated. They ignore them and then find that their programs are not portable. This is why pros get paid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.