java String与unicode
java String与unicode
java.nio.charset.Charset
public static Charset defaultCharset()
此方法的作用:返回java虚拟机的默认字符集,默认的字符集取决于操作系统的字符集。
java.lang.String
public byte[] getBytes()
此方法的作用:编码字符串到一个字节流序列,此时采用的编码是平台默认的编码,如果想获得指定编码的字节序列,可用下面这个方法:
public byte[] getBytes(String charsetName)
按照指定编码返回此字符串的编码格式。
证据如下:
String str = "我";
System.out.println(Integer.toHexString(codePoint));
byte[] bs = str.getBytes();
System.out.println(Charset.defaultCharset());
for (int i=0; i<bs.length; i++) {
System.out.print(bs[i] + " ");
}
System.out.println();
6211
GBK
-50 -46
当指定编码为UTF-8时:
6211
GBK
-26 -120 -111
当指定为UTF-16时:
-2 -1 98 17
注意此处输出了四个字节,是因为前面两个字节是用来表示字符的编码序列.
public int codePointAt(int index)
返回指定索引处的字符(Unicode 代码点)。该索引引用 char 值(Unicode 代码单元),其范围从 0 到length()- 1。
注意字符串在内存中是以unicode代码点的方式存储的。
public String(byte[] bytes, String charsetName)
throws UnsupportedEncodingException
构造一个新的 String,方法是使用指定的字符集解码指定的字节数组。新的 String 的长度是一个字符集函数,因此不能等于字节数组的长度。
public String[] split(String regex)
根据给定的正则表达式的匹配来拆分此字符串。
该方法的作用就像是使用给定的表达式和限制参数 0 来调用两因此,结果数组中不包括结尾空字符串。
例如,字符串 "boo:and:foo" 产生带有下面这些表达式的结果:
Regex
结果
:
{ "boo", "and", "foo" }
o
{ "b", "", ":and:f" }
试验证明:
String str = "boo:and:foo";
String[] tr = str.split(":");
for (String s : tr) {
System.out.println(s);
}
输出结果:
boo
and
foo
public String[] split(String regex,
in
相关文档:
在成功实现Java调用C++之后,接下来想到能否通过JNA实现Java调用Fortran,今天试验了一下,还是比较容易的。
网上有一个Java调用F95的例子,但是我考虑不仅要实现F95的调用,还要实现F77的调用,所以费了一些周折。
问题的关键在于F77为过程名自动添加了一个尾部的下划线,所以sub1这个过程,到Java一端,就变成了sub1_, ......
2.2 代码实现
下面给出了FlexBuilder工程的一个文件,设置了Flash的布局。
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
......
在Java
语言中, abstract class 和interface
是支持抽象类
定义的两种机制。正是由于这两种机制的存在,才赋予
了Java强大的 面向对象能力。abstract
class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进
行抽象类定义时对于abstract
class和interface的 ......
Let's begin by downloading the latest version of JRE (Java Runtime
Environment) from here
.
Just click on the Download link where it says Java Runtime
Environment (JRE) 5.0 Update
, then you�ll need to accept the license
and download the Linux self-extracting file
.By default, Fe ......
下面这段程序是实现了两个操作数加法的操作运算
/**
*the First Java
*@author wanglei
*@version 1.0
*/
import java.util.Scanner;
public class FirstJava{
public static void main(String[] args){
/**声明两个整型变量*/
int opA ......