JAVA常用类

ava.lang包中的常用类


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");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值