java - Maximum string length for given number of bytes -
java - Maximum string length for given number of bytes -
i need validate maximum length of string value going stored varchar2(4000 bytes) column in database. maximum length should take? assumed 2000, because java string encoded in utf-16, missing something? there case 2000-charactr string can take more 4000 bytes?
no, 2000 character string in java can't take more 4000 bytes of character data. may hear said utf-16 variable length encoding because can take 2 or 4 bytes represent unicode code point. while true, irrelevant because java's "character" not unicode code point, utf-16 code unit, 2 bytes. therefore, 2000-character string in java 4000 bytes of utf-16 data.
tangential warning: based on utilize of varchar2, seems me using oracle database. oracle has 2 main character set settings, database character set , national character set. first used varchar2 columns (among others), , other used nvarchar2 columns (again, among others). utf-16 is not supported utilize database character set, national character set. don't know info layer looks can't how impact you, can read this oracle document on character sets more information.
taken altogether, 2000-character string in java can end beingness more 4000 bytes elsewhere – if somewhere along way, gets converted different encoding.
java encoding utf-16
Comments
Post a Comment