473,397 Members | 1,961 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,397 software developers and data experts.

Keeping List member private, while using new 'for' syntax.

I have a class:
class MyClass
{
private List<int> myList;
public Iterator getIterator() { return myList.iterator(); }
}

When using an instance of MyClass, and I want to iterate over the
contents of myList, I call getIterator(), and use that iterator.

I would like to be able to use the new 1.5 syntax:
List<int> ls;
for( int val : ls )
{
System.out.println("value is "+ val);
}

I dont' see anyway of doing this, without having myList public or a
public acessor method.

Any ideas?
I haven't used Java a programming language in 3 years, so I could be
missing the obvious here.

Thanks,

~S
Jul 17 '05 #1
0 2298

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

Similar topics

8
by: Bruce | last post by:
OK, this won't compile saying it can't access private members declared in class F. I don't get it and even if I make the entire class public, it still says that. I realize it has something to do...
2
by: Thomas Matthews | last post by:
Hi, I have a hierarchy of classes and would like to create an array of pointers to member functions that could also contain pointers to the parent member functions as well. What is the syntax...
3
by: LinusLee | last post by:
class CAnalyzer { // attribute private: public: // behavior private: void NullFunc(NODE *pNode); void TraverseNode(NODE* pNode, void (*preFunc)(NODE *node), void (*postFunc)(NODE *node));
2
by: Barry Hynes | last post by:
G'Day folks, Have been working on this problem for quite some time and still no farther ahead. :( Here is my problem...bare with me i am very green :) I have to implement a Safe List,...
3
by: jut_bit_zx | last post by:
class A { public: A(); virtual ~A(){} .... private: int m_iarray; }
3
by: pmud | last post by:
Hi, I have 2 drop down lists on an asp.Net page. The 1st contains alphabets. When the user selects an alphabet frm the first list, the second drop down list should be populated with names from...
2
by: thekestrel | last post by:
Hi, I'm trying to iterate over the values of a list that has a templated type and I'm having trouble with the syntax, could anyone offer somehelp. Simplified version... #include <list>...
10
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
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
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
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,...
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...
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...
0
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...

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.