Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 关于binarySearch()的返回值
AchillesA

  very com



发贴: 35
积分: 0
于 2004-09-07 16:32 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

import java.util.*;
import com.bruceeckel.util.*;
class E_13_2 implements Comparable
{
private String s1;
private String s2;
E_13_2(){
}
E_13_2(String s1,String s2){
this.s1=s1;
this.s2=s2;
}
public boolean equals(Object o){
return (o instanceof E_13_2)&&(s2==((E_13_2)o).s2);
}
public int compareTo(Object obj)
{
String s = ((E_13_2)obj).s1;
return s1.compareTo(s);
}
public String toString(){
return "[s1:"+s1+"<>s2:"+s2+"]";
}
public static Arrays2.RandStringGenerator gen=
new Arrays2.RandStringGenerator(8);
public static Generator generator(){
return new Generator(){
public Object next(){
return new E_13_2((String)gen.next(),(String)gen.next());
}
};
}
}
public class E13Test
{
public static void main(String args[]){
E_13_2 e = new E_13_2();
E_13_2[] e13 = new E_13_2[10];
Arrays2.fill(e13,E_13_2.generator());
Arrays2.print("before sort() =>",e13);
int i=Arrays.binarySearch(e13,e13[4]);
System.out.println("binarySearch=>"+i);
Arrays.sort(e13);
Arrays2.print("after sort() =>",e13);
}
}

这里的binarySearach()的返回值为什么一会儿是正数,一会儿又是负数?而且负数的值也不同。




JBuilder使用技巧

话题树型展开
人气 标题 作者 字数 发贴时间
3506 关于binarySearch()的返回值 AchillesA 1198 2004-09-07 16:32

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923