Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

public static int binarySearch(byte[] a,  RSS feed

 
rahul mehra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;

public class Main {

public static void main(String args[])
{
byte[] b = {1,2,3,4,5};
Arrays.sort(b);
System.out.println(Arrays.binarySearch(b,*));
}
}

can you tell me * can be replaced by what method???
 
rahul mehra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;

public class Main {

public static void main(String args[])
{
byte[] b = {1,2,3,4,5};
Arrays.sort(b);
System.out.println(Arrays.binarySearch(b,*));
}
}

can you tell me * can be replaced by what character???
--------------------------------------------------------------------------------
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but I don't really understand what you are trying to achieve so the following may or may not be any use to you.

I suggest you have a look at the API docs for the binarySearch() method. It shows for a byte array as the first parameter you need to provide a byte for the second parameter. The second parameter is the byte that is searched for in the array and if found it's array index returned else if not found the point at which it would be inserted to maintain the sort order.
 
rahul mehra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi tony,

what i want to say that what should i enter at the '*' place ... like i enter character as 'a',string as "abc" and integer as 1.... so how should i enter that byte vaule..... if i write 1 it says found integer so i just want to know in what way should write it.....

public class Main {

public static void main(String args[])
{
byte[] b = {1,2,3,4,5};
Arrays.sort(b);
System.out.println(Arrays.binarySearch(b,*));
}
}
 
Jeremy Medford
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will find what you are looking for in the API docs under java.utils. The corresponding method description should indicate what to insert at the '*'.
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by deeksha mehra:
if i write 1 it says found integer so i just want to know in what way should write it.....
Yes a literal value of 1 is assumed to be an int, if you want it to be something else you have to put an explicit cast to the type you want eg


[ August 21, 2007: Message edited by: Tony Docherty ]
 
rahul mehra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks tony...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!