比如:String str = "中“;则是由中文字符组成的。
      String str1 = "oracle";则是由英文字符组成的。谢谢。

解决方案 »

  1.   

    String s="中文absdfwe中sfwef哈";
            int n=0;
            for (int i=0;i<s.length();i++)
            {
             if (s.charAt(i) >= 0x4e00 && s.charAt(i) <= 0x9fa5)
             n++;
            }
            System.out.print(n);
      

  2.   

    public class chinese1
    {
    public static void main (String [] args)
    {
    chinese ch=new chinese();
    boolean st=ch.hasChinese("谢谢");
    System.out.println(st);

    }
    public static boolean hasChinese(String value1)
      {
         byte[] valueBytes = value1.getBytes();  
         return value1.length() != valueBytes.length;
    }
    }汉字是双字节编码,它为了能够与英文字符分开,每个字节的最高位一定为1。如果是汉字,那么这个字节就是小于0的。这个函数就是通过这一原理实现的。所以要通过getBytes()转化为byte型,再比较与零的大小。
    getBytes()是把一个字符串转成一个byte数组,因为计算机的数据都是基于字符的,也就是说一个字符串实际上就是一个字符流,因此可以转为字符数组。汉字是双字节编码,英文是单字节编码。构成汉字的第一个字节是一个负值,第二个是正值。
    而构成英文字母的字节总是正值。至于为什么这么定义,我想你还是看一下unicode码的规范吧。
      

  3.   

    例如:
    public class chinese1
    {
    public static void main (String [] args)
    {
    chinese1 ch=new chinese1();
    boolean st=ch.hasChinese("谢谢");
    System.out.println(st);
    }
    public static boolean hasChinese(String value1) 
    {
        byte[] valueBytes = value1.getBytes(); 
        System.out.println(value1.length()); 
        System.out.println(valueBytes.length);
        return value1.length() != valueBytes.length;
    }
    }
    输出结果为:2,4,true!
      

  4.   

    见我的blog
    http://blog.csdn.net/westwin
    (原创)判断字符串是不是GB2312?
      

  5.   


    System.out.println(str.length()==str.getBytes().length?"English":"Chinese");