我的JAVA常用对象、方法

Object类
public String toString() :返回该对象的字符串表示。
public boolean equals(Object obj) :指示其他某个对象是否与此对象“相等”。
Date类
Date类构造方法
	Date():根据当前时间创建的日期对象
	Date(long date):根据给定的毫秒值创建对象,从1970 年 1 月 1 日 00:00:00 
	
Date类的成员方法
	public long getTime():获取的是毫秒值。从1970年1月1日 00:00:00开始的。
	public void setTime(long time):设置时间,给的是毫秒值。
DateFormat类
格式化(日期 -> 文本): Date -- String
	Date d = new Date();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
	String s = sdf.format(d);	
	
解析(文本 -> 日期):  String -- Date
	String str = "2080-08-08 12:23:45";
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Date d = sdf.parse(str);
Calendar类
静态方法
	public static Calendar getInstance() 获取一个日历对象。
成员方法
	public int get(int field) 获取某个字段的值
	public void set(int field,int value) 设置某个字段的值
	public void add(int field,int amount) 为某个字段增加/减少指定的值
Math类
public static int abs(int a) 获取参数a的绝对值:
public static double ceil(double a) 向上取整
public static double floor(double a) 向下取整
public static double pow(double a, double b) 获取a的b次幂
public static long round(double a) 四舍五入取整
Systema类
public static void exit(int status) 终止当前运行的Java虚拟机,非零表示异常终止
public static long currentTimeMillis() 返回当前时间(以毫秒为单位
BigInteger类
public BigInteger add(BigInteger value)     超大整数加法运算
public BigInteger subtract(BigInteger value)超大整数减法运算
public BigInteger multiply(BigInteger value)超大整数乘法运算
public BigInteger divide(BigInteger value)  超大整数除法运算,除不尽取整数部分
BigDecimal类
构造方法
	BigDecimal(double val) 将double类型的数据封装为BigDecimal对象
	BigDecimal(String val) 将BigDecimal的字符串表示形式转换为BigDecima-建议
普通方法
	public BigDecimal add(BigDecimal value) 加法运算
	public BigDecimal subtract(BigDecimal value) 减法运算
	public BigDecimal multiply(BigDecimal value) 乘法运算
	public BigDecimal divide(BigDecimal value) 除法运算
Arrays类
public static void sort(int[] a):按照数字顺序排列指定的数组
public static String toString(int[] a):返回指定数组的内容的字符串表示形式
包装类
构造方法及静态方法
    public Integer(int value) 根据 int 值创建 Integer 对象(过时)
    public Integer(String s) 根据 String 值创建 Integer 对象(过时)
    public static Integer valueOf(int i) 返回表示指定的int值的Integer实例
    public static Integer valueOf(String s) 返回保存指定String值的Integer对象
    
int类型和String类型互转
	 String s1 = 100 + "";  		 //int	--	String
	 int x = Integer.parseInt("100");//String	--	int
	 
String和char相互转换	
	String s2 = 'a' + "";  //char	--	String
	char ch = s2.charAt(0);//String	--	char 
String类
判断功能
boolean equals(Object obj):比较字符串的内容是否相同
boolean contains (CharSequence s)判断参数字符串在当前字符串中是否存在
boolean equalsIgnoreCase(String str):比较字符串的内容是否相同,忽略大小写
boolean startsWith(String str):判断字符串对象是否以指定的str开头
boolean endsWith(String str):判断字符串对象是否以指定的str结尾
获取功能
int length():获取字符串的长度,其实也就是字符个数
char charAt(int index):获取指定索引处的字符
int indexOf(String str):获取str在字符串对象中第一次出现的索引.如果不包含,则返回-1.
int lastIndexOf(String str)返回指定子字符串最后一次出现的字符串中的索引。 如果不包含,则返回-1
String substring(int start):从指定的下标开始一直截取到最后(包含这个下标对应的文字)
String substring(int start,int end):截取指定的范围的字符串(包含头,不包含尾)
转换功能
char[] toCharArray():把字符串转换为字符数组
String toLowerCase():把字符串转换为小写字符串
String toUpperCase():把字符串转换为大写字符串
拼接和替换功能
String concat (String str)将当前字符串与参数字符串进行拼接,返回一个新字符串。
String replace(CharSequence target,CharSequence replacement)字符串替换
去空格和分割功能
String trim():去除字符串两端空格	
String[] split(String str):按照指定符号分割字符串
字符串的遍历
for(int x=0; x<s.length(); x++) {
	System.out.println(s.charAt(x));
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值