array 转 int[]
arr.toArray(new int[n]);
array 翻转
Collections.reverse(arrayList);
int 最大值
int i = Integer.MAX_VALUE;
string 子串
s.substring(start,start+subLen);// 无大写!!!
[start_index,end+_index)
public class
一个文件中不能有两个public class,如果有,那必须包含一个内部类。
// 报错
public class T{
}
public class A{
}
--------------------
public class T{
public class A{
}
}
sort
给定label 和对应的number ,如何排序。
int[][]
arraylist 和int [][] 转换
LinkedList
char 类型
‘a’+1 如何得b
(char) (‘a’+2)
Date中12h 和24h的区别
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss sss");
HH 是24
hh是12
transient
transient:将不需要序列化的属性前添加关键字transient,序列化对象的时候,这个属性就不会被序列化。
final
private属性默认final
正则表达
\s+
匹配任何空字符串 包括 \n \t等,实际使用时,需要添加转义字符\ ,最终表达为\\s+
new 抽象类
抽象类是不能实例化的,但在new时,可以进行Override实现临时构建
public abstract class GenerationPartialStep{}
finalize = new GenerationPartialStep<NodeType, EdgeType>(next) {
@Override
public void call(final SearchLatticeNode<NodeType, EdgeType> node,
final Collection<Extension<NodeType, EdgeType>> extensions) {
// just call the next step of the outer GerenationStep
callNext(node, extensions); //extend the node and add to search tree
}
@Override
public void call(final SearchLatticeNode<NodeType, EdgeType> node) {
// the final step for extension generation is nothing else than
// stop
}
@Override
public void reset() {
// the final step for resetting is nothing else than stop
}
};
Object o = new Object()
ArrayList 的移除
ArrayList<Integer> a = new ArrayList<>();
a.add(10);
a.remove(10); // IndexOutOfBoundsException:
以上默认调用的是删除第10个元素,即remove(index)。这里由于类型问题导致重载出错,解决的方法有两种
修改数据的范型为Integer
a.remove((Integer)10);
第二种是找到index
a.remove(a.indexOf(10));
arrayList 元素个数与容量
ArrayList a=new ArrayList(10);
a.add(1);
arraylist.size();// 元素个数:1
不能直接获得当前的容量值,容量是由 this.elementData
这个属性来控制的,但外部不可见。
Comparable 与 Comparator
Comparable接口
1:所有可以 “排序” 的类都实现了java.lang.Comparable接口,Comparable接口中只有一个方法。
2:public int compareTo(Object obj) ;
该方法:
返回 0 表示 this == obj
返回整数表示 this > obj
返回负数表示 this < obj
https://blog.csdn.net/weixin_43505709/article/details/87908756
java.lang.comparable :
是在一个类定义的时候默认实现好的接口, 里面存在有一个 compareTo() 方法
class Person implements Comparable<Person>{
public int compareTo(Person o) {}
}
Person p[] = new Person[] ;
Arrays.sort(p);
omparator
java.util.comparator:
是进行挽救的比较接口, 需要单独定义一个比较规则类, 定义有 compare() 方法, equals() 方法
lass PersonComparator implements Comparator<Person>{
@Override
public int compare(Person o1, Person o2) {
if (o1.getAge() > o2.getAge()) {
return 1;
}else if (o1.getAge() < o2.getAge()) {
return -1;
}
return 0;
}
}
Person p[] = new Person[] ;
Arrays.sort(data,new PersonComparator());