1、StringBuilder:append(String str); 拼接字符串,相比string+的方式更高效;setCharAt(int i , char c);将第i个代码单元设置成c;insert(int offset , String str);在offset位置插入一个str字符串;delete(int startIndex , int endIndex);删除从startIndex位置到endIndex-1的内容;toString();将StringBuilder转成String输出。
2、Scanner:读取输入流,
构造方法 Scanner in = new Scanner(System.in);关联输入流
nextLine();读取输入的下一行内容,返回字符串;next();读取输入的下一个单词;nextInt();返回int类型,同理nextDouble();
hasNext();检测输入中是否包含其他单词;hasNextInt(); hasNextDouble();检测是否还有表示整数或浮点数的下一个字符序列。
Scanner属于明文读取,不适合读取密码。
3、Console:
Console cons = System.comsole();
cons.readLine("User name: ");
cons.readPassword("Password: ");
4、break标签中断循环模式:
read_data://标记标签
while(...){
...
for(...){
...
if(n>0) break read_data;//直接退出while循环,标签read_data
}
5、对象与类
面向对象:不必关心如何实现,只要能满足用户需求即可。
对象的三个主要特征:对象的行为,对象的状态,对象标识。
类之间最常见的关系:依赖,聚合,继承。一个类的方法操纵另一个类的对象,就是一个类依赖于另一个类,应该尽可能的减少依赖关系。
6、LocalDate:时间类
LocalDate newTime = LocalDate.of(1999, 12, 12);
int year = newTime.getYear();
int month = newTime.getMonth();
int day = newTime.getDayofMonth();
LocalDate time = newTime.plusDays(10);//在newtime的时间上增加10天,得到新的时间,time是1999,12,22.
int i = newTime.getDayofWeek().getValue();获取是周几,返回1-7。