java学习笔记3

类的访问修饰符只有两种:public和默认

在同一个类内,可以访问任何变量

 用static修饰的类成员或静态成员在定义时就分配了内存空间

静态的只能访问静态的,非静态的可以访问一切

 ============MATH类

math类的方法一般都是静态方法

=========string

字符串与整数之间的转换

1、字符串转数组:char c[]=str1.toCharArray() 其中str1是字符串
2、字符数组转字符串:String str2=new String(c,0,3) 将部分字符数组转成字符串
3、字符串转字节数组:byte b[]=str1.getBytes()
4、按字典顺序比较字符串大小:s1.compareTo(s2)>0
5、字符串与指定对象的比较:s1.equals(s2) s1.equalsIgnoreCase(s2)
6、startsWith() endsWith()
7、返回指定字符串索引:str1.indexof('b',2) str1.lastIndexOf('b',3)
8、返回子串:s1.substring(1) s1.substring(2,6)
9、替换字符串:s1.replace("ja","Ja") 双引号
s1.replace('a','A') 单引号
10、拆分字符串:split("b")

================StringBuffer    String对象不可变;StingBuffer对象可变

========StringBuild   也是可变的

=============Date

Date在java.util包中   import java.util.Date      CST:China Standard Time 就是北京时间

=========格式化日期:SimpleDateFormat

===========DateFormat 也可用于格式化日期

===================因为Calendar是抽象类,所以不能通过new实例化,但可以调用其静态方法得到一个对象

GregoianCalendar 是Calendar的子类

原文地址:https://www.cnblogs.com/testzcy/p/10393019.html