473,800 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arraylist Contains() Question

I am trying to add an object to an arraylist, but first I need to see
if the an object with a specified instance value already exists in the
arraylist. The Contains(obj) function checks the entire object but I
only need to check 1 instance variable in the object and return true or
false based on that.

My java experience tells me that it might have something to do with the
CompareTo() method, but I dont even know if the CompareTo method is
being used in the Contains() method. How would I go about creating a
Contains(string ). Can I not override some method to get the desired
result or do I have to manually iterate the arraylist and check each
object?

Any help would be appreciated.

thanks

Aug 23 '06 #1
0 1355

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

Similar topics

3
5297
by: Ton van den Heuvel | last post by:
Hi, I just noticed that ArrayList.Contains(Object obj) uses the Equals method of the object that is passed to the Contains method to check for equality with the object in the list. Wouldn't it be more logical to use the Equals method of the objects in the list? Regards, Ton van den Heuvel
1
1685
by: thechaosengine | last post by:
Hi all, Can anyone tell me how ArrayList.Contains works. The docs say that it tells you if an *object* is contained in the list. Now, by object do the docs mean the exact instance that you pass in, or some other way of working? I have a situation whereby i have a custom collection extended from an ArrayList, and I would like to be able to find out if a collection contains an instance
10
1528
by: C Downey | last post by:
Hello: I have an arraylist storing some very basic objects. The object is very basic, it has 2 properties : ID, and COUNT Before I add an object to the arraylist, I want to check if an object with that same ID already exists in the arraylist. If it does, I would like to increase the count of the matching object inside
3
11205
by: Dean Slindee | last post by:
I have loaded two forms into an ArrayList with the following statement: arrForm.Add(Me) 'in each form's Load method. Now I want to reference a form in the ArrayList. However, I must not be using the .Contains Method properly, because the If clause is never true. Dim frm As frmMain If arrForm.Contains(frm) Then
19
2462
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I would like to sort the arraylist based on object.name - is that possible? Thanks! Derek
8
9515
by: HarvSather | last post by:
C# VS2005 I have a class with 5 properties I am adding instances this class to an ArrayList I want to test to see if an instance is already in the ArrayList before attempting to add the item From my reading, it seems that I have to have an Equals method in my class
12
5132
by: Robert Hooker | last post by:
We are moving to .NET2.0 - and have noticed that .Contains() seems to be around 20% slower under NET2, compared to NET1.1. This code shows the issue: static void Main(string args) { System.Collections.ArrayList list = new System.Collections.ArrayList(); //Setup code //
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.