473,396 Members | 2,089 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,396 software developers and data experts.

Accessing a method inside of an object that is stored in a vector...

I have been trying to post to .help all day but nothing is going
through. Will try it here and hope it does....

I am trying to access a getData() method that simply returns a stored
integer value from an object that is stored in a vector. I have tried
to do this but cannot get the notation correct. I tried google groups
and the only thing I got from there was to pull the object from the
vector into a temperary object. That didnt work.

So, here is the code I have so far of making the temp object and
making sure it is actually pulling one out. I still connot figure out
how to access the getData() method.

Any hints are appreciated.

import java.util.Vector;

public class StackUser
{

public static void main(String argv[])
{

Vector vector = new Vector();

for (int i = 0; i < 100; i++)
vector.add(i, new StackNode());

System.out.println(vector.get(0));

Object tobj = vector.get(0);

System.out.println(tobj);
}
}

public class StackNode
{

private int value = 0;
public StackNode()
{
value = (int)(Math.random());
}

public int getData()
{
return value;
}

}
Jul 17 '05 #1
1 2021
da Vinci wrote:
I have been trying to post to .help all day but nothing is going
through. Will try it here and hope it does....

I am trying to access a getData() method that simply returns a stored
integer value from an object that is stored in a vector. I have tried
to do this but cannot get the notation correct. I tried google groups
and the only thing I got from there was to pull the object from the
vector into a temperary object. That didnt work.

So, here is the code I have so far of making the temp object and
making sure it is actually pulling one out. I still connot figure out
how to access the getData() method.


After getting the object from the Vector, you must cast it to the proper
type. Look up the cast syntax in your reference material.

If you use the so-called "generics" in Java 1.5, the cast is unnecessary.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

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

Similar topics

2
by: C Gillespie | last post by:
Dear All, I have 2 arrays var A1 = new Array(); A1 ="Y2"; var B1 = new Array(); B1 ="Y1"; B1 ="sink";
4
by: Tim | last post by:
An object 'X' is created inside a thread by object 'A'. The functionality of object 'X' is used only inside that thread. Inside the thread procedure, the object 'X's methods are called. That object...
2
by: Marcus | last post by:
I have a vector within a vector within a map. The innermost vector houses a struct with some ints and floats. The map keys off the secondary vector which acts as a wrapper for multiple vector...
11
by: food4uk | last post by:
Dear all : I am not good at programming, please give a hand. My data structure is very similar as an array. I actually can use the std::vector as container to organize my data objects. However,...
4
by: Rares Vernica | last post by:
Hi, How can I save a reference inside a container? For example I have: map<string, unsignedX; I would like to be able to save a reference to a position inside X. For a vector, the...
3
by: orkonoid | last post by:
Hello, I am having trouble with a Polymorphism issue using container classes. I have a longwinded and shortwinded version of my question: Shortwinded version: How can I store base class...
6
by: smoermeli | last post by:
#include <iostream> #include <vector> class Thing { private: int value; friend class Person; public: int getValue() { return value; } void...
18
by: Goran | last post by:
Hi @ all! Again one small question due to my shakiness of what to use... What is better / smarter? private: vector<MyClass_t* itsVector; OR...
2
by: thelamb | last post by:
Hello all, I have a question about deleting objects(the objects are stored in a vector) I Fill the vector as following: servObj.push_back(new CGame(serversh, game_id)); (1) ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.