1 byte (byte)=8 position (bit)

char=2 byte ( This is because char yes Java Reserved word in ,Java It's using Unicode, therefore char stay Java Medium is 16 Bitwise is 2 Bytes of .)

attach :

String str=" Ed "; Use byte[] bytes = str.getBytes(); And then 3 Bytes ;

char[] chars= str.value; And there's only chars There is only one stored in char, namely 2 Bytes ;

Why does this happen ?

First ,java One of them char It is indeed. 2 Bytes .java use unicode,2 Bytes to represent a character .
secondly ,byte[] bytes = str.getBytes(); And then 3 Bytes , This is not the same concept as before .

java Yes, it is unicode To represent characters ," Ed " This Chinese character is unicode Namely 2 Bytes .

String.getBytes(encoding) Method is to get the specified encoding byte An array of said ,

Usually gbk/gb2312 yes 2 Bytes ,utf-8 yes 3 Bytes .

If you don't specify encoding The system default encoding.

java position 、 byte 、 More related articles on character carding

  1. java The characters in , Bytes and encoding

    1. The origin of the coding problem , Understanding of related concepts 1.1 The development of character and coding From the perspective of computer support for multi language , It can be roughly divided into three stages :   System code explain System Stage 1 ASCII At first, computers only supported English , Other languages don't ...

  2. java Byte and character conversion operation in

    package com.ywx.io; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputSt ...

  3. Java IO: Byte and character arrays

    Link to the original text    author : Jakob Jenkov    translator :homesick The content list from InputStream perhaps Reader Read in the array from OutputStream perhaps Writer Write arrays in stay java in ...

  4. Java IO4: Character encoding

    Preface Character encoding , This doesn't belong to IO The content of , But the byte stream should be followed by the character stream , Since it's a character stream , That involves a " Character coded " problem , Considering that character encoding is not just about IO This piece of ,Java Many of the scenes in this series involve this concept ...

  5. JAVA The problem of garbled Chinese characters

    source :http://luzefengoo.blog.163.com/blog/static/1403593882012754428536/ JAVA The problem of garbled Chinese characters has always been a headache . Especially in WEB application ...

  6. Java Study the outline of knowledge system

    Sentiment It's strange , How could I want to write such a blog ——Java Language learning system , This is not a course that has been learned in University . I graduated from the computer science class , When I was in college, I held Java To learn , Whether it's for learning programming or getting a high score in the final exam , all ...

  7. java unicode Code point and code unit problems caused by supplementary characters

    Code points and code units java string There are two ways to determine characters , One is based on code points , One is based on code units , In short , Code points are real characters , Code units are by size, that is char Type length 2 A string divided into bytes . therefore length and chara ...

  8. Java The official account of WeChat is developed and sorted out

    Java The official account of WeChat is developed and sorted out Now the development of wechat public platform has become more and more common , This development needs to use wechat public platform . So make a simple note , It can also be regarded as some enlightenment for those children's shoes who have never stepped on the pit . I'll give a brief description in a few parts , I'll talk about it in detail later ...

  9. dried food ! hitting JVM Bottom —— Java Class Bytecode file parsing

    Catalog Preface How to read class file Basic concepts An unsigned number & surface Constant pool magic number (magic number) & Version number Constant pool Access signs Class index & Parent class index & Interface index set Field ...

  10. java The difference between byte stream and character stream Reprint

    Reprinted from :http://blog.csdn.net/cynhafa/article/details/6882061 java The difference between byte stream and character stream Byte stream is very similar to the use of character stream , Both except the operation code is not ...

Random recommendation

  1. MySQL Database optimization technology SQL Statement slow query location

    adopt show status Command to know all kinds of SQL The frequency of execution MySQL After successful client connection , By using show [session|global] status Command can provide server status information : Among them session ...

  2. establish xml when , Set up xml Coding problem

    OutputFormat format = OutputFormat.createPrettyPrint();    format.setEncoding("GBK"); XMLW ...

  3. Python And Python Imaging Library

    document:http://effbot.org/imagingbook/pil-index.htm http://pillow.readthedocs.io/en/3.1.x/index.htm ...

  4. c++ String de duplication

    ##### c++ String de duplication == demand == * Write a string filter function , If there are multiple identical characters in a string , Filter out characters that don't appear for the first time . > Input :"apache" Output :&q ...

  5. windows Hard disk optimization

    1. data collection ( The default family assignment is 4096 bytes. It's better to use only the results of the first calculation , After that, the value will increase all the time . Calculation software “Cluster Size Calculator”) ------------ System is w7 ...

  6. Customize QMenu

    Reference resources : http://blog.csdn.net/qq1623803207/article/details/77449884 http://blog.sina.com.cn/s/blog_a6fb6c ...

  7. django.db.utils.OperationalError: (1049, "Unknown database 'djangodb'")

    DATABASES = { 'default': { 'ENGINE':'django.db.backends.mysql', 'NAME': 'mysql', 'USER':'root', 'PAS ...

  8. 6、 ... and 、K3 WISE Developing a plug-in 《 direct SQL Report development novice guide - BOM Cost statement 》

    ======================== Catalog : 1. direct SQL report form ======================== 1. direct SQL report form With BOM Take the cost report as an example , Deploy in the sales module , Need to buy [ Kingdee ...

  9. pandas DataFrame Indexes (iloc And loc The difference between )

    Pandas--ix vs loc vs iloc difference 0. DataFrame DataFrame The construction of depends on the following three parameters : data: Tabular data : index: Row index : columns: Name : ...

  10. The first 3 Chapter file I/O(6)_ Advanced file operations : File lock

    7. Advanced file operations : File lock (1) File lock classification Classification basis type explain By function Shared read lock The file descriptor must be read open A process has a read lock , Other processes can also read with read lock Exclusive write lock The file descriptor must be written open In a process ...