常用类及其常用方法

1.String

/*
* String 的常用方法
* 1. String concat(String str) 将指定字符串连接到此字符串的结尾。 
* 2. int length() 返回此字符串的长度。 1
* 3. boolean equals(Object anObject) 将此字符串与指定的对象比较。 
* 4. boolean equalsIgnoreCase(String anotherString) 将此 String 与另一个 String 比较,不考虑大小写。 
* 5. String toUpperCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
* 6. String toLowerCase() 使用给定 Locale 的规则将此 String 中的所有字符都转换为小写。
* 7. boolean startsWith(String prefix) 测试此字符串是否以指定的前缀开始。 
* 8. boolean endsWith(String suffix) 测试此字符串是否以指定的后缀结束。 
* 9. int indexOf(int ch) 返回指定字符在此字符串中第一次出现处的索引 
* 10. int indexOf(int ch, int fromIndex) 返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。 
* 11. int lastIndexOf(String str) 返回指定子字符串在此字符串中最右边出现处的索引。 
* &&12. int lastIndexOf(String str, int fromIndex) 返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始(反向搜索)。 
* 13. String substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。 
* 14. String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串。 
* 15. char charAt(int index) 返回指定索引处的 char 值。 
* 16. String trim()返回字符串的副本,忽略前导空白和尾部空白 
* 17. int compareTo(String anotherString) 按字典顺序比较两个字符串。 
* 18. int compareToIgnoreCase(String str) 按字典顺序比较两个字符串,不考虑大小写。 
* 
* 19. String replace(CharSequence target, CharSequence replacement) 使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串。 
* 
* 20. String[] split(String regex) 根据给定正则表达式的匹配拆分此字符串。
*/

2.System

/**
 * 位于java.lang包下
 *   属性:
 *      in:“标准”输入流。
 *      out:“标准”输出流。
 *      err:标准”错误输出流。
 *   out 与 err区别
 *   方法:
 *       exit();
 *       gc();
 *
 */

3.Runtime

/**
 * Runtime类
 *   位于 java.lang
 *   运行时每个JVM对应一个Runtime实例,此实例由Runtime为其实例化
 *    本类中没有构造方法 ,其实本类的构造方法私有化 ,也就是在类中有一个方法可以返回本类的实例对象
 *
 */
public class Test1 {
	public static void main(String[] args) {
		//The constructor Runtime() is not visible
//		Runtime rt1=new Runtime();
		Runtime rt1=Runtime.getRuntime();
		System.out.println(rt1);
		Runtime rt2=Runtime.getRuntime();
		System.out.println(rt2);
		
		System.out.println("最大存储空间:"+rt1.maxMemory());
		System.out.println("剩余存储空间:"+rt1.freeMemory());
		
		rt1.gc();//垃圾回收机制
		System.out.println("剩余存储空间:"+rt1.freeMemory());
		
		try {
//			rt1.exec("notepad");
			rt1.exec("calc");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

4.Calendar

package com.qf.calender.test;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Calendar(抽象类)

 * java.util
 * GregorianCalendar子类
 * 属性:
 *    YEAR
 *    MONTH
 *    DAY_OF_MONTH
 *  方法:
 *    
 *     int get(int field)   返回给定日历字段的值。 
 */
public class Test1 {
	public static void main(String[] args) {
		Calendar c=new GregorianCalendar();
//		c.get(field)
		System.out.println(c);
		System.out.println(c.get(Calendar.YEAR));//2017
		System.out.println(c.get(Calendar.DAY_OF_MONTH));//19
		System.out.println(c.get(Calendar.MONTH));//6  0
		System.out.println(c.get(Calendar.DATE));//19 
		System.out.println(c.get(Calendar.WEEK_OF_MONTH));//5
		System.out.println(c.get(Calendar.DAY_OF_WEEK_IN_MONTH));//3
		
		c.add(Calendar.MONTH, -2);
		System.out.println(c.get(Calendar.MONTH));
	}
}

5.Character

/**
 * Character字符类
 * 1.static boolean isDigit(char ch)   确定指定字符是否为数字。 
 * 2.static boolean isLetter(char ch) 确定指定字符是否为字母。 字母=英文+汉字
 * 3.static boolean isLowerCase(char ch)    确定指定字符是否为小写字母。 
 * 4.static boolean isUpperCase(char ch)     确定指定字符是否为大写字母。 
 * 5.static char toLowerCase(char ch) 
          使用取自 UnicodeData 文件的大小写映射信息将字符参数转换为小写。 
 * 6.static char toUpperCase(char ch) 
          使用取自 UnicodeData 文件的大小写映射信息将字符参数转换为大写。 
 * @author liuxin
 * 
 *
 */
public class Test2 {
	public static void main(String[] args) {
		char c='1';
		System.out.println(Character.isDigit(c));
		char c1='男';
		System.out.println(Character.isLetter(c1));
		char c2='A';
		System.out.println(Character.isUpperCase(c2));
		
		System.out.println(Character.toLowerCase(c2));
	}
}

6.Math

/**
 * Math
 * java.lang
 * 常用方法:
 *     static double pow(double a, double b) 返回第一个参数的第二个参数次幂的值。 
 *     static double sqrt(double a) 返回正确舍入的 double 值的正平方根。 
 *     static int abs(int a)  返回 int 值的绝对值。 
 *     static double ceil(double a) (向上取整) 返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数。 
 *     static double floor(double a) (向下取整) 返回最大的(最接近正无穷大)double 值,该值小于等于参数,并等于某个整数。 
 *     static int max(int a, int b)  返回两个 int 值中较大的一个。 
 *     static int min(int a, int b)  返回两个 int 值中较小的一个。 
 *     static int round(float a)   返回最接近参数的 int。 
 *     static double random()  返回带正号的 double 值,该值大于等于 0.0 且小于 1.0。 
 * @author liuxin
 *
 */
public class Test {
	public static void main(String[] args) {
		double area=Math.PI*Math.pow(5, 2);
		System.out.println("圆的面积是:"+area);
		
		int num=Math.abs(0);
		System.out.println(num);
		
		double n=Math.sqrt(16);
		System.out.println(n);
		
		n=Math.ceil(12.1);
		System.out.println(n);
		
		n=Math.floor(12.9);
		System.out.println(n);
		
		n=Math.round(12.4);
		System.out.println(n);
		
		n=Math.max(12.7, 89.7);
		System.out.println(n);
		
		n=Math.min(12.7, 89.7);
		System.out.println(n);
	}
}

转载于:https://www.cnblogs.com/ssjifm/p/7210512.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值