• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

public static int binarySearch(byte[] a,

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
--------------------------------------------------------------------------------
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,*));
}
}
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks tony...
reply
    Bookmark Topic Watch Topic
  • New Topic