常用Java片段

时间:2022-12-14 05:55:37

1. 字符串与整型的相互转换

  1. String a = String.valueOf(2);   //integer to numeric string
  2. int i = Integer.parseInt(a); //numeric string to an int

2,得到当前方法的名字

public class MethodName {
    private void IamAMethod(){
        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        System.out.println(methodName);   
    }
public static void main(String[] args) {
MethodName mName=new MethodName();
mName.IamAMethod();
}
}

3,