本文主要是记录一下JAVA:
1.Arrays.的几个用法:
fill:数组全部置一个数
sort:排序
binarySearch:二分查找
2.Map的用法:
Map<Integer,Integer> ma = new HashMap<Integer,Integer>(); ma.put(key, val); int val = ma.get(key); // key没有的话,为null,所以需要先判断是否为null
3.Math.的用法
4.文件操作:
FileInputStream in = new FileInputStream("src\data.txt");
DataInputStream fin = new DataInputStream(in);
String s = fin.readLine();
FileOutputStream out = new FileOutputStream("src\ans.txt");
DataOutputStream fout = new DataOutputStream(out);
fout.writeBytes("string");
Scanner cin = new Scanner(new File("file.txt"));
5.日期操作:
设置格式:DateFormat format = new SimpleDateFormat("yyyy:MM:dd");
得到某个日期:Date a = format.parse(string);
得到两个日期相差的天数:int day =(int) ( (a.getTime()-b.getTime())/(24*60*60*1000) );
得到从0000:00:00开始经过num毫秒数的日期:a.setTime(num);
得到某个格式format的日期的字符串格式:String str = format.format(a);
6.foreach:
int [] a = new int[100];
for(int c:a)
a[i] = i;