byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
2.Integer :封装了基本的int类型的类
属性:int的最大值:Integer.MAX_VALUE
int的最小值:Integer.MIN_VALUE
方法:将整数转成字符串:Integer.toString(100);
将整数转成对应进制的字符串:
Integer.toString(100,2);
将纯数字字符串转成整数:Integer.valueOf("12345");
Integer.paserInt("1110001",2);
3. Math类:
Math.abs(t);
Math.max(a,b);
Math.min(a,b);
Math.pow(a,b);
Math.sqrt(t);
Math.random();
4.System类:
System.err.println();
System.out.println();
System.in;
public class mathh { public static void main(String[] args) { int a=Math.abs(-34); int b=Math.max(2,3); int c=Math.min(3,4); float d=(float) Math.pow(2,3); float e=(float) Math.sqrt(4); long f=(long) Math.random(); System.out.println(a); System.out.println(b); System.out.println(c); System.out.println(d); System.out.println(e); System.out.println(f); System.err.println(e);//红字错误输出 System.exit(0); } }
5.// 系统当前时间,以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:要复制的个数
public class b { public static void main(String[] args) { int[] a={1,2,3,4,5}; int[] b=new int[10]; System.arraycopy(a, 1, b, 4 , 2); System.arraycopy(a,2,b,4,2); } }
6.字符串类:
String
字符集标准:一个字符是由哪些字节构成,有多套不同的标准
ISO-8859 西欧字符集,不包含全角字符
GB2312/GBK 简体中文字符集
Big5 繁体中文字符集
UTF-8 基于Unicode编码的字符集
ANSI表示采用当地默认的字符集标准
7.构造方法
String(byte[] bytes)
String(byte[] bytes,"字符集编码")
String(byte[] bytes,start,length)
String(char[] c)
String(char[] c,start,length)
import java.io.UnsupportedEncodingException; public class c { public static void main(String[] args) throws UnsupportedEncodingException { //字符串转成字节数组 String s="aajhsk"; byte[] bs=s.getBytes(); System.out.println(bs); //字符串按照指定字符集转成字节数组 byte[] bs1=s.getBytes("UTF-8"); System.out.println(bs1); //将字符串转成字符数组 char[] bs2=s.toCharArray(); System.out.println(bs2); //将字符串中的部分字符复制到字符数组 String s1="ABCDEFG"; //char[] a=s1.getChars(1,4,char[],3); // char c=s1.charAt(2); System.out.println(c); String s2="sbdshbf"; int len=s2.length(); System.out.println(len); // String d="aaghgask fhdskhgjkd"; //判断子字符串在大字符串中第一次出现的位置 long a=s.indexOf("s"); //判断子字符串在大字符串中最后一次出现的位置 long b=s.lastIndexOf("d"); System.out.println(a); System.out.println(b); //替换字符串 String s3="I love you"; String d1=s3.replace("love", "miss"); String e=s3.concat(s1); System.out.println(d1); System.out.println(e); //截取字符串 String f=s3.substring(2,5); System.out.println(f); //大小写转换 String g="ABCDefgh"; String s5=g.toLowerCase(); String s6=g.toUpperCase(); String s7=s5.substring(0,4); String s8=s6.substring(4,8); String ss=s7.concat(s8); System.out.println(s5); System.out.println(s6); System.out.println(ss); //去除空格项 输出长度 String S=" i miss you "; String s0=S.trim(); int len1=S.trim().length(); System.out.println(s0); System.out.println(len1); //将其他类型的数据转换成字符串类型 String t=String.valueOf(01000100); System.out.println(t); } }