File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Accessing variables in an array element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessing variables in an array element" Watch "Accessing variables in an array element" New topic
Author

Accessing variables in an array element

Malcolm White
Greenhorn

Joined: Nov 10, 2002
Posts: 15
Hello everyone,
I have an array which is an instance of a class and is made up of 10 elements (indeces). The class that it is an instance of has two private variables. What I'm trying to do is that after the elements are populated in the array, I want to swap two of them around.
Is there a way to use a syntax like:
int first_value=array[3].value1
int second_value=array[3].value2
to get the two parts (variables) of the element in differenet variables of primitive types?
The above code doesn't seem to work. I remember being able to use "dot" after an object to access both its functions and variables. Thanks to all who can help.
Regards.
[ November 29, 2002: Message edited by: Malcolm White ]
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
It would help if you could post your code. We could probably help better.


Author and Instructor, my book
Malcolm White
Greenhorn

Joined: Nov 10, 2002
Posts: 15
Thanks. Here's my code


The 'Card' class has two private variables declared in it: value and suit.
Hope someone can help. Thanks.
[ November 29, 2002: Message edited by: Malcolm White ]
[ November 29, 2002: Message edited by: Malcolm White ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing variables in an array element