TreeSet的实现方法,between and 和substring;

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有但是?没有;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值