Java常用方法函数总结

判断字符串为空的方法
public static boolean isNull(String... obj){
                for(String s : obj){
                      if(s == null || "".equals(s)){
                     return true;
                   }
                }
                return false;
            }





判断一个字符是否包含在一个数组字符中
private boolean isInStringArray(String string, ArrayList<String> arrayList) {
        for (String oneString : arrayList) {
            if (string.equals(oneString)) {
                return true;
            }
        }
        return false;
    }



android判断EditText输入的数字、中文还是字母方法
String txt = edInput.getText().toString();

  Pattern p = Pattern.compile("[0-9]*");
   Matcher m = p.matcher(txt);
   if(m.matches() ){
   Toast.makeText(Main.this,"输入的是数字", Toast.LENGTH_SHORT).show();
   }
   p=Pattern.compile("[a-zA-Z]");
   m=p.matcher(txt);
   if(m.matches()){
   Toast.makeText(Main.this,"输入的是字母", Toast.LENGTH_SHORT).show();
   }
   p=Pattern.compile("[\u4e00-\u9fa5]");
   m=p.matcher(txt);
   if(m.matches()){
   Toast.makeText(Main.this,"输入的是汉字", Toast.LENGTH_SHORT).show();
   }


String txt = edInput.getText().toString();

  Pattern p = Pattern.compile("[0-9]*");
   Matcher m = p.matcher(txt);
   if(m.matches() ){
   Toast.makeText(Main.this,"输入的是数字", Toast.LENGTH_SHORT).show();
   }
   p=Pattern.compile("[a-zA-Z]");
   m=p.matcher(txt);
   if(m.matches()){
   Toast.makeText(Main.this,"输入的是字母", Toast.LENGTH_SHORT).show();
   }
   p=Pattern.compile("[\u4e00-\u9fa5]");
   m=p.matcher(txt);
   if(m.matches()){
   Toast.makeText(Main.this,"输入的是汉字", Toast.LENGTH_SHORT).show();
   }




华为手机管家黑名单判定流程

public static byte[] imsiToKey(String imsi) {
        if (imsi == null) {
            return null;
        }
        int len = imsi.length();
        int lenKey = len / 2 + 1;
        boolean even = len % 2 != 0;

        byte[] key = new byte[lenKey];
        for (int i = 0; i < lenKey; i++) {
            if (i == 0) {
                key[0] = (byte) (0x00 + (imsi.charAt(0) - '0') * 16 + 9);
            } else if (i == (lenKey - 1) && !even) {
                key[i] = (byte) (0x00 + 0xF0 + (imsi.charAt(len - 1) - '0'));
            } else {
                key[i] = (byte) (0x00 + (imsi.charAt(i * 2) - '0') * 16 + (imsi.charAt(i * 2 - 1) - '0'));
            }
        }

        MTKlog.i(TAG, "imsiToKey is : " + key.toString());
        return key;
    }



转16进制
public static String bytesToHexString(byte[] src) {
        StringBuilder stringBuilder = new StringBuilder();
        if (src == null || src.length <= 0) {
            return null;
        }
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();
    }


如何把 int、short 变量与 byte[] 的转换
private static byte[] intToByteArray(int data) {
    return ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(data).array();
}
 
private static byte[] shortToByteArray(short data) {
    return ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(data).array();
} 
 
private static short byteArrayToShort(byte[] b) {
    return ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getShort();
}
     
private static int byteArrayToInt(byte[] b) {
    return ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getInt();
}








  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值