Java中的每一个基本类型都对应了一个类类型
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
Integer:
常用属性 MAX_VALUE
MIN_VALUE
构造方法 Integer b = new Integer(100);
Integer b1 = new Integer("0110");
常用方法
int t = Integer.parseInt("10");
//其它进制转十进制
int t = Integer.parseInt("10",进制);
//十进制转其它进制
String s = Integer.toBinaryString(-127);
String s1 = Integer.toOctalString(127);
String s2 = Integer.toHexString(127);
String s=100+"";
Math类
PI
abs(a);
max(a,b);
min(a,b);
pow(a,b);
sqrt(a);
random();
Scanner类
java.util包中的类
Scanner sc = new Scanner(System.in);
sc.next();
sc.nextLine();
sc.nextInt();
sc.nextFloat();
sc.nextDouble();
sc.nextShort();
sc.nextLong();
sc.nextBoolean();
sc.nextByte();
Random类 随机数类
Random rd = new Random();
int t = rd.nextInt(100);
String类
String s = "abc";
String s1 = "abc";
String s2 = new String("abc");
String s3 = new String("abc");
字符集标准
ISO8859标准字符集 不能表示中文
UTF-8 基于Unicode编码的字符集
GBK 简体中文
GB2312
GB18030
Big5 繁体中文
将字节数组转换成字符串
String(byte[] bs);
String(byter[] bs,String charsetName);
将字节数组转换成字符串
String(byte[] bs);
String(byter[] bs,String charsetName);
String(byte[] bs,int off,int length);
//将字符数组转换成字符串
String(char[] cs);
String(char[] cs,int off,int length);
字符串转成字节数组
getBytes();
getBytes(String charsetName);
获得指定的字符
charAt(0);
将字符串转成字符数组
toCharArray();
字符串的操作
匹配
equals(String s);是否相等
equalsIgnoreCase(String s);是否相等,忽略大小写
startsWith(String s); 是否以s开头
endsWith(String s); 是否以s结尾
contains(String s); 是否包含s
截取
subString(int startIndex);从start位置开始截取,包含start
subString(int startIndex,int endIndex);
//获取指定的字符或者字符串出现的位置
indexOf('.');
lastIndexof('.')
替换
replace(String old,String new);
replaceFirst(String old,String new);
切割
split("a");