A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
arrayList access to Object's instance variables
kavundamani senthil
Greenhorn
Joined: Feb 28, 2008
Posts: 16
posted
Sep 16, 2008 05:54:00
0
In the program below how can i access the fields bankName, accId from the object o ?
import java.util.*;
public class sorting {
String
bankName ;
int accId;
public void addaccount(String bankName,int accId)
{
this.bankName = bankName;
this.accId = accId;
}
public static void main(String args[])
{
TreeSet
t = new
TreeSet
();
sorting s = new sorting();
sorting s1 = new sorting();
s.addaccount("IndianBank",100);
s1.addaccount("IndianBank",99);
t.add(s);
t.add(s1);
Iterator it = t.iterator();
while(it.hasNext())
{
object o = it.next();}
}
}
Paul Somnath
Ranch Hand
Joined: May 19, 2008
Posts: 177
posted
Sep 16, 2008 06:34:00
0
public static void main(String args[]) { TreeSet t = new TreeSet(); sorting s = new sorting(); sorting s1 = new sorting(); s.addaccount("IndianBank", 100); s1.addaccount("IndianBank", 99); t.add(s); Iterator it = t.iterator(); while (it.hasNext()) { sorting obj =(sorting) it.next(); System.out.println(obj.bankName); System.out.println(obj.accId); } }
Preparing for SCJP 6.0
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: arrayList access to Object's instance variables
Similar Threads
Treeset throwing ClassCastException
ClassCast Exception while using TreeSet
TreeXxx VS PriorityQueue
Doubt in Comparable interface
treeset doesnt take any parameters?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter