满意答案
svisvj496
2018.06.13
采纳率:40% 等级:9
已帮助:113人
/*方法1*/ String str = "123本"; if( str.length() < str.getBytes().length ){ System.out.println("含全角文字"); }
/*方法2*/public static void main(String[] args){ List list = new ArrayList(); list.add("1"); list.add("a"); list.add("本"); list.add("3"); for( int i = 0; i < list.size(); i ++ ){ System.out.println( ((String)list.get(i)).getBytes().length ); } }
/**方法3* 最根本的就是现在java中的char是可以动态的(1-2字节) * 那么要想判定就很简单了,如果char的长度超过了1就是,如果是1就不是 */public class test { /** * @param args */ public static void main(String[] args) { String a = "AAAA"; String b = "AAAA"; System.out.println(checkHalf(a)); System.out.println(checkHalf(b)); } public static boolean checkHalf(String str) { byte[] Char; for(int i = 0; i < str.length(); i++) { try{ Char = (new Character(str.charAt(i)).toString()).getBytes("MS932"); }catch(Exception e) { return false; } if(Char.length == 1) { return true; } } return false; } }
00分享举报