这次博客主要是总结下之前的学习
public static void main (string[] args)
psvm+tab = public static void main缩写
sout + tab=system.out.println()的缩写
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
Scanr函数的另一种表达形式,用于键盘输入
int a=Integer.parseInt(reader.readLine());
将Int a 转换成integer类型
readLine用于读取文件中的所有行
String name1 = reader.readLine();
return Double.parseDouble(br.readLine());
将所选行中的数据转换成double类型。
return Boolean.parseBoolean(br.readLine());
将所选行中的数据转换成boolean类型。
if (name1.equals(name2)) 检测两个变量是否相同
boolean。此类型变量只能取两个值:true 和 false
boolean m = (a > b);
if (m)
System.out.println(a);
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
protected void finalize() throws Throwable
ArrayList list = new ArrayList();
while (true) {
String s = reader.readLine();
if (s.isEmpty()) break;
list.add(s);
}
创建一个哈希表:
HashSet set = new HashSet<>();
HashMap<String, String> map = new HashMap<>();
for (Map.Entry<String, String> pair : map.entrySet()) {
System.out.println(pair.getKey() + " - " + pair.getValue());
} **遍历哈希表中的所有数据
Java Map.values()方法:获取Map集合中的所有键值对象
常见的异常类型:
Collections.sort(arraylist); 排序
Collections.reverse(arraylist); 重组
TimeoutException 超时异常
SQLException SQL异常");
ParseException 解析异常
Exception 非运行时异常
NullPointerException 空指针异常
ArrayIndexOutOfBoundsException 处理数组时的异常
NumberFormatException 处理数字时发生异常
IndexOutOfBoundsException 使用列表集合时发生异常
NullPointerException 处理映射集合时发生异常
除了RuntimeException与其子类,以及错误(Error),其他的都是检查异常(绝对的大家族)。
//行内注释
//多行注释**
/** */文档注释
命名规范:
1.见名知意
2.驼峰命名(变量,方法)
3.类 首字母大写,驼峰命名
4.常量 大写+下划线
5.不要使用中文拼英