Results 1 to 5 of 5
  1. #1
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default how does public static <AnyType extends Comparable<? super AnyType>> int binarySearch

    Ok, I have some code like this:

    Java Code:
    public static <AnyType extends Comparable<? super AnyType>> int binarySearch( AnyType [] a, AnyType x )
    How does that work? And how do I instantiate it, I tried:

    astringArray [] = new String[2];

    astringArray[0]="hi";
    astringArray[1]="Find Me";

    binarySearch coolSearch=new binarySearch(astringArray, "Find Me");

    but it returned an error binarySearch(String [], String) not Found

    I'm a bit confused with this implementation,

    Any help would be appreciated.

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    binarySearch is not a class
    it is a method
    you should import java.util.Arrays;
    and use method as Arrays.binarySearch(...);

  3. #3
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default

    No I don't want to import a Binary Search, i'm trying to create my own so I understand them better.

  4. #4
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default

    Wait I see what you are saying, sorry about that, you're right.

  5. #5
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default

    ok, so basically I needed to not create a new method just a call like so

    search=binarySearch(stringArray, "text");

Similar Threads

  1. Replies: 9
    Last Post: 11-22-2008, 11:03 PM
  2. Replies: 5
    Last Post: 10-06-2008, 12:11 AM
  3. Creating a Comparable object
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:38 PM
  4. interface Comparable<T> problem
    By Lennon-Guru in forum New To Java
    Replies: 3
    Last Post: 03-05-2008, 12:17 AM
  5. Implements MyClass extends JFrame
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 03:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •