473,666 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check if an object already exists

oll3i
679 Contributor
how to check if an object already exists and return reference to that object
Apr 5 '07 #1
59 32804
RedSon
5,000 Recognized Expert Expert
Can you please describe your question in more detail?
Apr 5 '07 #2
oll3i
679 Contributor
i have to write a flower shop
i need to check if a client already exists so that i dont add a new one
Apr 6 '07 #3
hirak1984
316 Contributor
[font=Verdana][size=2]your question is not yet clear.[/size][/font]
[font=Verdana][size=2]In general we compare the instance of the object with null,[/size][/font]
[font=Verdana][size=2]to see if it exists or not...[/size][/font]
i have to write a flower shop
i need to check if a client already exists so that i dont add a new one
Apr 6 '07 #4
prometheuzz
197 Recognized Expert New Member
i have to write a flower shop
i need to check if a client already exists so that i dont add a new one
Exists in what? An array, a java.util.List some other java.util.Colle ction?
Apr 6 '07 #5
oll3i
679 Contributor
in a list of clients
Apr 6 '07 #6
JosAH
11,448 Recognized Expert MVP
in a list of clients
Well, read all about it in the API docs for the List.contains(. ..) method.

kind regards,

Jos

ps. Bookmark The API docs or download them for easy reference.
Keep those docs at your fingertips whenever you want to write code.
Apr 6 '07 #7
oll3i
679 Contributor
[code]
if(klienci.cont ains(klient)){
int index=klienci.i ndexOf(klient);

klient=klienci. get(index);
}

[code]

but it doesnt find the client in the list
Apr 7 '07 #8
hirak1984
316 Contributor
can we know the errors you are getting?
[code]
if(klienci.cont ains(klient)){
int index=klienci.i ndexOf(klient);

klient=klienci. get(index);
}

[code]

but it doesnt find the client in the list
Apr 7 '07 #9
prometheuzz
197 Recognized Expert New Member
if(klienci.cont ains(klient)){
int index=klienci.i ndexOf(klient);

klient=klienci. get(index);
}

but it doesnt find the client in the list
When doing this, you're looping through the list twice: once in the contains(...) method, and another looptwhen using the indexOf(...) method.
I suggest doing this:
Expand|Select|Wrap|Line Numbers
  1. int index = klienci.indexOf(klient);
  2.  
  3. if(index != -1) {
  4.   klient = klienci.get(index);
  5. else {
  6.   // 'klient' is not in the list 'klienci'
  7. }
Apr 7 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2459
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what happens if one of those objects, when it is created, takes a reference to the object that contains it? Do bad things happen? class McShow {
2
11854
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an error message and stop the process every time someone loads the script after the table is created because that would mean the page could only ever run once which of course not the solution I was looking for. I simply want to know how I can check...
2
6020
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x < 20; x++) { document.all('mySpan'+x).style.display = "inline"; } But I don´t know how many SPAN elements there are, so I need to set x to a
9
7249
by: Carl Fenley | last post by:
I am successfully adding stored procedures to an Access database. However, I need to be able to check if the stored procedure of the same name already exists. Is there a way to do this other than waiting for the OleDbException caused when adding one that already exists? Here is the code snippet: Private Sub CreateStoredProcedures()
4
3010
by: jes | last post by:
hi, i have an open & delete btn. onclick of open as visio drawing opens in visio & onclick of delete the drawing gets deleted from the filesystem. The problem is i am unable to perform these actions if the file is already opened in another instance of visio. how do i check if it's already opened and then throw an error msg? thanks
14
46239
by: John Salerno | last post by:
What is the best way to check if a file already exists in the current directory? I saw os.path.isfile(), but I'm not sure if that does more than what I need. I just want to check if a file of a certain name exists before the user creates a new file of that name. Thanks.
3
11038
by: byeung | last post by:
Hi, I am trying to check if a particular record already exists in an Access database through Excel vba code. Through code obtained at another forum, I got the following: *********************************************************************** Sub TheButton()
2
35080
by: Larry | last post by:
Thanks in advance. what is the C# equivalent of the VB.net IsNothing(object) function? just trying to check to see if an object instance already exists. does someone have an example? *** Sent via Developersdex http://www.developersdex.com ***
0
6452
by: bharathreddy | last post by:
This article will explain you how to check weather a column already exists in a table before you add the column to the table using alter command. Using the system tables you can check to see weather a column already belongs to a specific table. SYSCOLUMNS is the system table which stores all the table columns information, from this column you can check weather a specific column exists in a specific table. ...
0
8443
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
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6192
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
5663
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();...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
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.