Treeset排序
A:自然排序:要在自定义类中实现Comparerable<T>接口 ,并且重写compareTo方法
TreeSet<Student> ts = new TreeSet<>();
Student 要实现comparerable<Student>接口(因为该对象没有自然排序,所以要自己写)
实现里面的compareTo(Student s)方法
B:比较器排序:在自定义类中实现Comparetor<t>接口,重写compare方法
TreeSet<Student> ts = new TreeSet<>(new MyComparetor());
在创建TreeSet时候传入一个对象,制定排序规则;
这个对象MyComparetor要实现comparetor<Student>接口,实现里面的compare(Student s1,Student s2)方法;
between and 是[];
String.substring(startindex,endindex);
返回的是从开始下标到结束下标的字符串,包括左边的但是不包括右边的,左闭右开;
String s = "abcd?efgh";
int index = s.indexOf("?");
String s1 = s.substring(0,index);//s1 : abcd a有但是?没有;
A:自然排序:要在自定义类中实现Comparerable<T>接口 ,并且重写compareTo方法
TreeSet<Student> ts = new TreeSet<>();
Student 要实现comparerable<Student>接口(因为该对象没有自然排序,所以要自己写)
实现里面的compareTo(Student s)方法
B:比较器排序:在自定义类中实现Comparetor<t>接口,重写compare方法
TreeSet<Student> ts = new TreeSet<>(new MyComparetor());
在创建TreeSet时候传入一个对象,制定排序规则;
这个对象MyComparetor要实现comparetor<Student>接口,实现里面的compare(Student s1,Student s2)方法;
between and 是[];
String.substring(startindex,endindex);
返回的是从开始下标到结束下标的字符串,包括左边的但是不包括右边的,左闭右开;
String s = "abcd?efgh";
int index = s.indexOf("?");
String s1 = s.substring(0,index);//s1 : abcd a有但是?没有;