473,767 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with array lists

4 New Member
Dear prob solver,

i have a problem with array lists. i am using array lists for adding objects. i just want to know, when you are adding an object to an arraylist whats the value u pass to the add method???

eg:
i have a class call vertex and i want to add an object from that class. so to add that object how to i add that to the arraylist??? do i need to pass the string id or pass an instant of the relevant class??? The code is below

vertex v;
string source_id

arraylist a = new arraylist();
a.add(source_id ??) or a.add(v)??? what is correct?

plz send me an answer asap... cz its for my final year project that i need to submit on next wek.. thnx aloot,,,,,,,,
Ran
Jul 27 '07 #1
5 1493
nateraaaa
663 Recognized Expert Contributor
Dear prob solver,

i have a problem with array lists. i am using array lists for adding objects. i just want to know, when you are adding an object to an arraylist whats the value u pass to the add method???

eg:
i have a class call vertex and i want to add an object from that class. so to add that object how to i add that to the arraylist??? do i need to pass the string id or pass an instant of the relevant class??? The code is below

vertex v;
string source_id

arraylist a = new arraylist();
a.add(source_id ??) or a.add(v)??? what is correct?

plz send me an answer asap... cz its for my final year project that i need to submit on next wek.. thnx aloot,,,,,,,,
Ran
An array list can hold an array of any type of object that you would like.

for an array of strings you would do something like this.
Expand|Select|Wrap|Line Numbers
  1. string[] arrNames = {"Smith","Jones","Ryan"};
  2. ArrayList a = new ArrayList();
  3. for (int i = 0; i<arrNames.Length; i++)
  4. {
  5. a.Add(arrNames[i].Trim());
  6. }
if you had an array of vertexes try something like this
Expand|Select|Wrap|Line Numbers
  1. object[] arrVertex = {vertex1, vertex2, vertex3};
  2. ArrayList b = new ArrayList();
  3. for(int i = 0; i<arrVertex.Length; i++)
  4. {
  5. b.Add(arrVertex[i]);
  6. }
Give these examples a try and let us know if you encounter any other issues.

Nathan
Jul 27 '07 #2
Plater
7,872 Recognized Expert Expert
If you want to add the vertex object you would add an instance of it.
Expand|Select|Wrap|Line Numbers
  1. vertex v;
  2. string source_id
  3.  
  4. ArrayList a = new ArrayList();
  5. //a.Add(source_id);
  6. //or 
  7. //a.Add(v);<-this one
  8. //??? what is correct? 
  9.  
You should note that any changes made to v after it was added to the ArrayList will not be reflected in the object stored. So make your changes first and do a .Add() after.
Jul 27 '07 #3
Ranmini
4 New Member
Can u plz check the below code and let me know whether its right or wrong???? i have a class called vertex and created an object of that class and those set methods are methods from the vertex class...is this code is correct??? what does that mean actually??? i wanted to know whether the desired operation happens throught this code
thnx aloooot...

ArrayList open_list= new ArrayList();
Vertex ObjvertID = new Vertex();

string[] arrayA= VerticesAdjecnt .ReturnAdjectVe rtArray(sourceI D);
for (int v = 0; v < arrayA.Length; v++)
{
ObjvertID.set_v ert_id(arrayA[v]);
ObjvertID.set_p arent_node_id(s ourceID);
open_list.Add(O bjvertID);

}
Jul 27 '07 #4
Ranmini
4 New Member
--------------------------------------------------------------------------------

Can u plz check the below code and let me know whether its right or wrong???? i have a class called vertex and created an object of that class and those set methods are methods from the vertex class...is this code is correct??? what does that mean actually??? i wanted to know whether the desired operation happens throught this code
thnx aloooot...

ArrayList open_list= new ArrayList();
Vertex ObjvertID = new Vertex();

string[] arrayA= VerticesAdjecnt .ReturnAdjectVe rtArray(sourceI D);
for (int v = 0; v < arrayA.Length; v++)
{
ObjvertID.set_v ert_id(arrayA[v]);
ObjvertID.set_p arent_node_id(s ourceID);
open_list.Add(O bjvertID);

}
















If you want to add the vertex object you would add an instance of it.
Expand|Select|Wrap|Line Numbers
  1. vertex v;
  2. string source_id
  3.  
  4. ArrayList a = new ArrayList();
  5. //a.Add(source_id);
  6. //or 
  7. //a.Add(v);<-this one
  8. //??? what is correct? 
  9.  
You should note that any changes made to v after it was added to the ArrayList will not be reflected in the object stored. So make your changes first and do a .Add() after.
Jul 28 '07 #5
RoninZA
78 New Member
ArrayList open_list= new ArrayList();
Vertex ObjvertID = new Vertex();

string[] arrayA= VerticesAdjecnt .ReturnAdjectVe rtArray(sourceI D);
for (int v = 0; v < arrayA.Length; v++)
{
ObjvertID.set_v ert_id(arrayA[v]);
ObjvertID.set_p arent_node_id(s ourceID);
open_list.Add(O bjvertID);

}
This looks like it should work just fine...? Although, you'll have to add a new declaration of your ObjvertID at the start of each loop... otherwise you might be getting funny problems with memory being shared between the objects in the ArrayList. So:
Expand|Select|Wrap|Line Numbers
  1. ArrayList open_list= new ArrayList();
  2. Vertex ObjvertID = new Vertex();
  3.  
  4. string[] arrayA= VerticesAdjecnt.ReturnAdjectVertArray(sourceID);
  5. for (int v = 0; v < arrayA.Length; v++) 
  6. {
  7.     ObjvertID = new Vertex();
  8.     ObjvertID.set_vert_id(arrayA[v]);
  9.     ObjvertID.set_parent_node_id(sourceID);
  10.     open_list.Add(ObjvertID);
  11. }
  12.  
Jul 30 '07 #6

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

Similar topics

8
3866
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE, char*buf); Users will get a Numeric Array object and can change its values (and actually change the underlying C array).
9
4339
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side vbscript reads the database and populates a listbox on the page with the first field from each record in the recordset. This works fine. - User selects an option on the listbox and, using the OnChange, I
21
4180
by: Jeff Thies | last post by:
I'd like to randomly sort an array. A good method?
8
2568
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating an alternative to pop-up windows in a web page. The code I have works (sort of). The problem is that I can move these layers around when I move the mouse slowly, however, if I move it fast the web browser looses track of the motion and leaves the...
7
2049
by: Jim Lewis | last post by:
I'm trying to move a function into pyrex for speed. The python side needs to pass a list to the pyrex function. Do I need to convert to array or something so pyrex can generate tight code? I'm not clear how to do this.
5
2285
by: bruce | last post by:
hi... i'm trying to deal with multi-dimension lists/arrays i'd like to define a multi-dimension string list, and then manipulate the list as i need... primarily to add lists/information to the 'list/array' and to compare the existing list information to new lists i'm not sure if i need to import modules, or if the base python install i have is sufficient. an example, or pointer to examples would be good...
5
2193
by: Tobiah | last post by:
I checked out the array module today. It claims that arrays are 'efficient'. I figured that this must mean that they are faster than lists, but this doesn't seem to be the case: ################ one.py ############## import array a = array.array('i')
36
2902
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray looks like this: typedef struct { vector origin; /* vector is an array of 3 doubles */
6
5949
by: Jillian Calderon | last post by:
Hi. How do I define a 2d list? For instance, to define a 4 by 5 list, I wanted to do this: n=4 m=5 world = However, it gives me an invalid syntax error saying the index is out of range.
0
9571
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
9404
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
10009
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
9959
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,...
1
7381
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
6651
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
5279
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
3929
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
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.