java.lang包中的常用类

1.和基本数据类型对应的8中类类型
byte /Byte
short /Short
int /Integer
long /Long
float /Float
double /Double
char /Character
boolean /Boolean


Integer:封装了基本的int类型的类

属性:
int的最大值:Integer.MAX_VALUE
int的最小值: Integer.MIN_VALUE

方法:
将整数转成字符串:Integer.toString(100);
将整数转成对应进制的字符串:Integer.toString(100,2);
将纯数字字符串转成整数:Integer.valueOf("12345");
Integer.valueOf("1100011",2);

将纯数字字符串转成整数 :Integer.paserInt("12345");
Integer.paserInt("1100011",2);

案例:
1.将证整数97转成二进制,八进制,十六进制
2.将二进制转成十进制

---------------------------------------------------------------------

Math类:
属性:E
PI

方法: Math.abs(t);
Math.max(a,b);
Math.min(a,b);
Math.pow(a,b);
Math.sqrt(a);
Math.random();

----------------------------------------------------------------------
System类
System.err.println();
System.out.println();
System.in

正常退出程序:System.exit(0);

// 系统当前时间,以1970-01-01 00:00:00:0000开始计算到现在经历过的毫秒数
long t = System.currentTimeMillis();

int[] a = { 1, 2, 3, 4, 5 };
int[] b = new int[10];
//复制数组
System.arraycopy(a, 1, b, 4, 3);
参数1:源数组
参数2:源数组中的起始下标位置
参数3:目标数组
参数4:目标数据中的起始下标位置
参数5:要复制的个数


----------------------------------------------------------------------
字符串类:
String
字符集标准:一个字符是由哪些字节构成,有多套不同的标准
ISO-8859 西欧字符集,不包含全角字符
GB2312/GBK  简体中文字符集
Big5   繁体中文字符集
UTF-8      基于Unicode编码的字符集

ANSI表示采用当地默认的字符集标准

构造方法
String(byte[] bytes)
String(byte[] bytes,"字符集编码")
String(byte[] bytes,start,length)

String(char[] c)
String(char[] c,start,length)

方法:
字符串转成字节数组    byte[] bs = s.getBytes();
字符串按照指定字符集转成字节数组byte[] bs = s.getBytes("UTF-8");
将字符串转成字符数组    char[] c = s.toCharArray();
将字符串中的部分字符复制到字符数组  "ABCDEFG".getChars(1,4,char[],3);
获得指定位置的字符 char c = s.charAt(下标);
        按字典顺序比较两个字符串                 compareTo(String anotherString)
                  按字典顺序比较两个字符串,不考虑大小写    compareToIgnoreCase(String str)
                 判断在字符串中是否包含另外一个字符串      contains(CharSequence s)
                判断字符串是不是以某一个后缀结尾 endWith(String s);   
       判断字符串是不是以某一个前缀开头        startWidth(String s);
判断两个字符串是否相等 equals(String s)
判断两个字符串是否相等,忽略大小写 equalsIgnoreCase(String s);
判断子字符串在大字符串中第一次出现的位置 s.indexOf(S1);
判断子字符串在大字符串中最后一次出现的位置 s.lastIndexOf(S1);
得到字符串的字符长度 int len = s.length();
替换字符串 s.replace("old","new");
截取字符串 s.substring(startIndex);
s.substring(startIndex,endIndex);
全部转成小写字符 toLowerCase();
全部转成大写字符 toUpperCase();
去掉字符串首尾的空白字符 trim();
将其他类型的数据转换成字符串类型 String.valueOf(任意类型);
切割字符串 s.splite(",");
import java.util.Scanner;

public class demo {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入字符串:");
		String str = sc.nextLine();
		System.out.println(str);
		
		String[] s  = str.split(" ");
		for(int i=0;i<s.length;i++){
			System.out.println(s[i]);
		}
	}

}

猜你喜欢

转载自780577645.iteye.com/blog/2344697