object string math 方法

object方法功能进行简单的描述:
(一)Object():默认构造方法
(二)clone():创建并返回此对象的一个副本
(三)equals():指示某个其他对象是否与此对象相等
(四)finalize():当垃圾回收器确定不存在对该对象的更多引用时,由对象的垃圾回收器调用此方法
(五)getClass():返回一个对象的运行时类
(六)hashCode():返回该对象的哈希值
(七)notify():唤醒此对象监视器上等待的单个线程
(八)notifyAll():唤醒此对象监视器上等待的所有线程
(九)toString():返回该对象的字符串表示
(十)wait():导致当前的线程等待,直到其它线程调用此对象的notify()或notifyAll()
(十一)wait(long timeout):导致当前的线程等待调用此对象的notify()或notifyAll()
(十二)wait(long timeout, int nanos):导致当前的线程等待,直到其他线程调用此对象的notify()或notifyAll(),或其他某个线程中断当前线程,或者已超过某个实际时间量
(十三)registerNatives():对本地方法进行注册

作者:ZytheMoon
来源:CSDN
原文:https://blog.csdn.net/zythemoon/article/details/78396736
版权声明:本文为博主原创文章,转载请附上博文链接!
Math类
public class MathDemo {

  1.  public static void main(String args[]){
    
  2.  	/**
    
  3.  	 * abs求绝对值
    
  4.  	 */
    
  5.  	System.out.println(Math.abs(-10.4));	//10.4
    
  6.  	System.out.println(Math.abs(10.1));		//10.1
    
  7.  	/**
    
  8.  	 * ceil天花板的意思,就是返回大的值,注意一些特殊值
    
  9. 	 */
    
  10. 	System.out.println(Math.ceil(-10.1));	//-10.0
    
  11. 	System.out.println(Math.ceil(10.7));	//11.0
    
  12. 	System.out.println(Math.ceil(-0.7));	//-0.0
    
  13. 	System.out.println(Math.ceil(0.0));		//0.0
    
  14. 	System.out.println(Math.ceil(-0.0));	//-0.0
    
  15. 	/**
    
  16. 	 * floor地板的意思,就是返回小的值
    
  17. 	 */
    
  18. 	System.out.println(Math.floor(-10.1));	//-11.0
    
  19. 	System.out.println(Math.floor(10.7));	//10.0
    
  20. 	System.out.println(Math.floor(-0.7));	//-1.0
    
  21. 	System.out.println(Math.floor(0.0));	//0.0
    
  22. 	System.out.println(Math.floor(-0.0));	//-0.0
    
  23. 	/**
    
  24. 	 * max 两个中返回大的值,min和它相反,就不举例了
    
  25. 	 */
    
  26. 	System.out.println(Math.max(-10.1, -10));	//-10.0
    
  27. 	System.out.println(Math.max(10.7, 10));		//10.7
    
  28. 	System.out.println(Math.max(0.0, -0.0));	//0.0
    
  29. 	/**
    
  30. 	 * random 取得一个大于或者等于0.0小于不等于1.0的随机数
    
  31. 	 */
    
  32. 	System.out.println(Math.random());	//0.08417657924317234
    
  33. 	System.out.println(Math.random());	//0.43527904004403717
    
  34. 	/**
    
  35. 	 * rint 四舍五入,返回double值
    
  36. 	 * 注意.5的时候会取偶数
    
  37. 	 */
    
  38. 	System.out.println(Math.rint(10.1));	//10.0
    
  39. 	System.out.println(Math.rint(10.7));	//11.0
    
  40. 	System.out.println(Math.rint(11.5));	//12.0
    
  41. 	System.out.println(Math.rint(10.5));	//10.0
    
  42. 	System.out.println(Math.rint(10.51));	//11.0
    
  43. 	System.out.println(Math.rint(-10.5));	//-10.0
    
  44. 	System.out.println(Math.rint(-11.5));	//-12.0
    
  45. 	System.out.println(Math.rint(-10.51));	//-11.0
    
  46. 	System.out.println(Math.rint(-10.6));	//-11.0
    
  47. 	System.out.println(Math.rint(-10.2));	//-10.0
    
  48. 	/**
    
  49. 	 * round 四舍五入,float时返回int值,double时返回long值
    
  50. 	 */
    
  51. 	System.out.println(Math.round(10.1));	//10
    
  52. 	System.out.println(Math.round(10.7));	//11
    
  53. 	System.out.println(Math.round(10.5));	//11
    
  54. 	System.out.println(Math.round(10.51));	//11
    
  55. 	System.out.println(Math.round(-10.5));	//-10
    
  56. 	System.out.println(Math.round(-10.51));	//-11
    
  57. 	System.out.println(Math.round(-10.6));	//-11
    
  58. 	System.out.println(Math.round(-10.2));	//-10
    
  59. }
    }

java中String的常用方法
java中String的常用方法
1、length() 字符串的长度
  例:char chars[]={‘a’,‘b’.‘c’};
    String s=new String(chars);
    int len=s.length();

2、charAt() 截取一个字符
  例:char ch;
    ch=“abc”.charAt(1); 返回’b’

3、 getChars() 截取多个字符
  void getChars(int sourceStart,int sourceEnd,char target[],int targetStart)
  sourceStart指定了子串开始字符的下标,sourceEnd指定了子串结束后的下一个字符的下标。因此, 子串包含从sourceStart到sourceEnd-1的字符。接收字符的数组由target指定,target中开始复制子串的下标值是targetStart。
  例:String s=“this is a demo of the getChars method.”;
    char buf[]=new char[20];
    s.getChars(10,14,buf,0);

4、getBytes()
  替代getChars()的一种方法是将字符存储在字节数组中,该方法即getBytes()。

5、toCharArray()

6、equals()和equalsIgnoreCase() 比较两个字符串

7、regionMatches() 用于比较一个字符串中特定区域与另一特定区域,它有一个重载的形式允许在比较中忽略大小写。
  boolean regionMatches(int startIndex,String str2,int str2StartIndex,int numChars)
  boolean regionMatches(boolean ignoreCase,int startIndex,String str2,int str2StartIndex,int numChars)

8、startsWith()和endsWith()  startsWith()方法决定是否以特定字符串开始,endWith()方法决定是否以特定字符串结束

9、equals()和==
  equals()方法比较字符串对象中的字符,运算符比较两个对象是否引用同一实例。
  例:String s1=“Hello”;
    String s2=new String(s1);
    s1.eauals(s2); //true
    s1
s2;//false

10、compareTo()和compareToIgnoreCase() 比较字符串

11、indexOf()和lastIndexOf()
  indexOf() 查找字符或者子串第一次出现的地方。
  lastIndexOf() 查找字符或者子串是后一次出现的地方。

12、substring()  它有两种形式,第一种是:String substring(int startIndex)
         第二种是:String substring(int startIndex,int endIndex)

13、concat() 连接两个字符串

14 、replace() 替换
  它有两种形式,第一种形式用一个字符在调用字符串中所有出现某个字符的地方进行替换,形式如下:
  String replace(char original,char replacement)
  例如:String s=“Hello”.replace(‘l’,‘w’);
  第二种形式是用一个字符序列替换另一个字符序列,形式如下:
  String replace(CharSequence original,CharSequence replacement)

15、trim() 去掉起始和结尾的空格

16、valueOf() 转换为字符串

17、toLowerCase() 转换为小写

18、toUpperCase() 转换为大写

19、StringBuffer构造函数
  StringBuffer定义了三个构造函数:
  StringBuffer()
  StringBuffer(int size)
  StringBuffer(String str)
  StringBuffer(CharSequence chars)
  
  (1)、length()和capacity()    一个StringBuffer当前长度可通过length()方法得到,而整个可分配空间通过capacity()方法得到。
  
  (2)、ensureCapacity() 设置缓冲区的大小
    void ensureCapacity(int capacity)

(3)、setLength() 设置缓冲区的长度
    void setLength(int len)

(4)、charAt()和setCharAt()
    char charAt(int where)
    void setCharAt(int where,char ch)

(5)、getChars()
    void getChars(int sourceStart,int sourceEnd,char target[],int targetStart)

(6)、append() 可把任何类型数据的字符串表示连接到调用的StringBuffer对象的末尾。
    例:int a=42;
      StringBuffer sb=new StringBuffer(40);
      String s=sb.append(“a=”).append(a).append("!").toString();

(7)、insert() 插入字符串
    StringBuffer insert(int index,String str)
    StringBuffer insert(int index,char ch)
    StringBuffer insert(int index,Object obj)
    index指定将字符串插入到StringBuffer对象中的位置的下标。

(8)、reverse() 颠倒StringBuffer对象中的字符
    StringBuffer reverse()

(9)、delete()和deleteCharAt() 删除字符
    StringBuffer delete(int startIndex,int endIndex)
    StringBuffer deleteCharAt(int loc)

(10)、replace() 替换
    StringBuffer replace(int startIndex,int endIndex,String str)

(11)、substring() 截取子串
    String substring(int startIndex)
    String substring(int startIndex,int endIndex)

例子:
//String所给出的方法均可以直接调用
public class Test{
public static void main(String[] args){
String s = “Welcome to Java World!”;
String s1 = " sun java “;
System.out.println(s.startsWith(“Welcome”));//字符串以Welcome开头
System.out.println(s.endsWith(“World”));//字符串以World结尾
String sL = s.toLowerCase();//全部转换成小写
String sU = s.toUpperCase();//全部转换成大写
System.out.println(sL);
System.out.println(sU);
String b = s.substring(11);//从第十一位开始
System.out.println(b);
String c = s.substring(8,11);//从第八位开始在第十一位结束
System.out.println©;
String d = s1.trim();//去掉首尾的空格
System.out.println(d);
String s2 = “我是程序员,我在学java”;
String e = s2.replace(“我”,“你”);
System.out.println(e);
int f = 5;
String s3 = String.valueOf(f);
System.out.println(s3);
String s4 = “我是,这的,大王”;
String[] g = s4.split(”,");
System.out.println(g[0]);
当把字符串转换成基本类型时,例如,int,integer.praseInt(String s)
当把基本类型转换成字符串时,例如,static String valueOf(int i)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值