###封装类中封装了,可能常用的方法。且有用的方法整理:
#character
| 函数名 |功能 |
| --- | --- |
| public static int digit(char ch, int radix) | Returns the numeric value of the character <code>ch</code> in the specified radix. ch转成各种进制表达的数字,超过范围则返回-1. |
|public static int getNumericValue(char ch)|the numeric value of the character, as a nonnegative <code>int</code> value; <br>-2 if the character has a numeric value that is not a nonnegative integer; <br>-1 if the character has no numeric value.|
|public static boolean isDigit(char ch)||
|public static boolean isLetter(char ch)||
|public static boolean isLetterOrDigit(char ch)||
|public static boolean isUpperCase(char ch)||
|public static boolean isLowerCase(char ch)||
```
public class Main{
public static void main(String[] args) {
System.out.println(Character.isLetter(' '));
System.out.println(Character.isLetter('a'));
System.out.println(Character.isLetter('='));
System.out.println( Character.digit('f', 16));
System.out.println( Character.digit('f', 15));
System.out.println(Character.getNumericValue('a'));
System.out.println(Character.getNumericValue('z'));
}
}
输出:
false
true
false
15
-1
10
35
```
#Integer
| 函数名 |描述 |
| --- | --- |
| public static String toString(int i, int radix) | * Returns a string representation of the first argument in the radix specified by the second argument. <br>如果radix 在[2,35]中才有效,不然就默认成10进制|
|public static String toOctalString(int i)|转8进制|
|public static String toHexString(int i)|转16进制|
|public static String toBinaryString(int i) |转2进制|
|public static int numberOfLeadingZeros(int i)|Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified <tt>int</tt> value. Returns 32 if the specified value has no one-bits in its two's complement representation, in other words if it is equal to zero.|
|public static int numberOfTrailingZeros(int i)|Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified <tt>int</tt> value. Returns 32 if the specified value has no one-bits in its two's complement representation, in other words if it is equal to zero.|
|public static int highestOneBit(int i)|@return an <tt>int</tt> value with a single one-bit, in the position of the highest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.|
|public static int lowestOneBit(int i) |@return an <tt>int</tt> value with a single one-bit, in the position of the lowest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.|
|public static int bitCount(int i)|@return the number of one-bits in the two's complement binary representation of the specified <tt>int</tt> value.|
|public static int reverse(int i)|Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified <tt>int</tt>value|
|public static int parseInt(String s) throws NumberFormatException|Parses the string argument as a signed decimal integer.@exception NumberFormatException if the string does not contain a parsable integer.|
|public static int parseInt(String s, int radix)throws NumberFormatException|Parses the string argument as a signed integer in the radix specified by the second argument<br>*Examples:<br>* <blockquote><pre><br>* parseInt("0", 10) returns 0<br>* parseInt("473", 10) returns 473<br>* parseInt("-0", 10) returns 0<br>* parseInt("-FF", 16) returns -255<br>* parseInt("1100110", 2) returns 102<br>* parseInt("2147483647", 10) returns 2147483647<br>* parseInt("-2147483648", 10) returns -2147483648<br>* parseInt("2147483648", 10) throws a NumberFormatException<br>* parseInt("99", 8) throws a NumberFormatException<br>* parseInt("Kona", 10) throws a NumberFormatException<br>* parseInt("Kona", 27) returns 411787<br>* </pre></blockquote>|
```
public class Main{
public static void main(String[] args){
System.out.println(Integer.toString(8, 2));
System.out.println(Integer.toString(8,16));
System.out.println("numberOfLeadingZeros");
System.out.println(Integer.numberOfLeadingZeros(8));
System.out.println(Integer.numberOfLeadingZeros(0));
System.out.println(Integer.numberOfLeadingZeros(-1));
System.out.println(Integer.numberOfLeadingZeros(-2123));
System.out.println("highestOneBit");
System.out.println(Integer.highestOneBit(16));
System.out.println(Integer.highestOneBit(15));
System.out.println(Integer.highestOneBit(8));
System.out.println(Integer.highestOneBit(7));
System.out.println(Integer.highestOneBit(0));
System.out.println(Integer.highestOneBit(-1));
System.out.println(Integer.highestOneBit(-2123));
System.out.println("bitCount");
System.out.println(Integer.bitCount(16));
System.out.println(Integer.bitCount(3));
System.out.println(Integer.bitCount(-3));
System.out.println("reverse");
System.out.println(Integer.reverse(128));
System.out.println(Integer.reverse(16777216));
System.out.println(256*256);
}
}
输出:
1000
8
numberOfLeadingZeros
28
32
0
0
highestOneBit
16
8
8
4
0
-2147483648
-2147483648
bitCount
1
2
31
reverse
16777216
128
65536
- 参考资料
- 容器的实现
- ArrayList、LinkedList与Vector的区别
- Map,Set,List,Queue,Stack的特点与用法
- HashMap的实现
- HashMap和ConcurrentHashMap差别
- HashMap和HashTable的区别
- fast fail
- java 实用方法
- Collections中实用的函数
- ArrayList中实用的函数
- Integer和Character
- Properties类的简单使用
- XML实用解析
- 从jar包中读取文件信息
- java自带base64加密解密
- java机制
- 分派
- 反射
- 类加载机制
- java中一个对象的初始化
- 泛型
- 自动装箱,拆箱与遍历循环
- 偏向于语法
- new int[]
- new boolean[]
- Switch能否用string做参数
- equals与==的区别
- 泛型对象数组
- Enum的用法
- String、StringBuffer与StringBuilder的区别
- try catch finally
- finalize方法
- object有哪些公用方法
- Java的四种引用,强弱软虚,用到的场景
- java访问修饰符
- Hashcode的作用
- 九种基本数据类型
- java对象大小
- 数组长度
- 动态代理的一个例子
- java.lang.NoClassDefFoundError
- ThreadLocal