473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to use ArrayList.BinarySearch if the object is not found.

I have a list of strings and I would like to insert them in order as they
come up.

I am trying to use ArrayList.BinarySearch which (theoretically) returns the
negative bitwise compliment. And I should be able to find the index of the
element one higher than where I should insert.

How?

I'm not getting it.

I created an arraylist with strings "1", "3", "5" and when I did a
BinarySearch for "2" I get (-100001). The bitwise compliment of which is
(100000), not (1) like I should expect.

And a BinarySearch for "4" returns (-200002).

I've got no idea what this is doing. How do you use this function?

Thanks in advance,
Tom Padilla
Nov 21 '05 #1
2 1484

When I run the following code:

Dim al As New ArrayList

al.Add("1")
al.Add("3")
al.Add("5")

MsgBox((Not al.BinarySearch("4")).ToString)
I get 2 in the MsgBox. Are the items in your ArrayList sorted? They
must be sorted for the BinarySearch method to work.

Nov 21 '05 #2
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...

When I run the following code:

Dim al As New ArrayList

al.Add("1")
al.Add("3")
al.Add("5")

MsgBox((Not al.BinarySearch("4")).ToString)
I get 2 in the MsgBox. Are the items in your ArrayList sorted? They
must be sorted for the BinarySearch method to work.


That was it.

Just "NOT".

Thanks man. I was using XOR, XOR -1, -1 + XOR, NOR, NOR x -1... all kinds
of crap.

Thanks,
Tom P.
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Homa | last post by:
I can' believe my own eye, but it happens...there is a bug in ArrayList.BinarySearch!! It should be such a simple function...... Here is the detail. (I'm using C#, don't know if this is C#'s...
6
by: Eric Eggermann | last post by:
I'm going batty trying to figure out why this is not working. I'm trying to find all objects within a class derived from CollectionBase which meet a certain criteria, but the search seems to be...
8
by: Sek | last post by:
Folks, I have an ArrayList of integers. I have sorted the list already. Now, i want to find the index of the first element that is greater than a given number. How to accomplish this in C#?
4
by: Mike Dole | last post by:
I have an arraylist like the one with the Guitar Class sample in Q316302. Dim MycolliCol as arraylist Private Sub FillArray() MyColliCol.Add(New Colli(1, "STUK", 0)) MyColliCol.Add(New...
9
by: Paul Nations | last post by:
I've got arraylists of simple classes bound to controls. I need to search through those arraylists to set the correct SelectedItem in the control. The code looks like: Public Class...
10
by: JohnR | last post by:
I have an arraylist of string values. I would like to search the arraylist to find the index of a particular string and I would like the search to be case insensitive. dim al as new arraylist...
6
by: AAJ | last post by:
Hi all I have some objects that I add to an ArrayList. Each object is from the same class and has methods etc. Each can be identified by a unique property, in this case PK e.g. PK =1 for...
1
by: garyusenet | last post by:
My Array list contains a collection of InternetExplorer object. One of properties of this object is HWND. I'm trying to search my arraylist for the InternetExplorer object that has a certain...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.