class odject in list
I have three class. In first class i have get and set methods, in second class i have a list of objects of first class then after main class i want to read the objects values but it will shows only the memory allocation by the object not given the class object values.
my classes is like that--->
1st class:-
public class preAuthor {
private long id;
private String name;
public preAuthor(String name){
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String list) {
this.name = list;
}
}
2nd class-->
import java.util.List;
public class Author{
private List<preAuthor> preAuth;
public List<preAuthor> getAuthor() {
return preAuth;
}
public void setAuthor(List<preAuthor> preAuth) {
this.preAuth = preAuth;
}
}
Main class:-
public class mainclass{
public static void main(String args[]) {
preAuthor auth=new preAuthor(null);
auth.setName("sud");
auth.setName("shekhar");
ArrayList<preAuthor> lst=new ArrayList<preAuthor>();
lst.add(auth);
Author au=new Author();
au.setAuthor(lst);
Iterator<preAuthor> itr=au.getAuthor().iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}
please help me to get the values.
Thanks
View Answers
October 19, 2011 at 10:53 AM
Hi it seems that you are printing the object to print the object value here you will have to override the toString() method of object class here or you will have to call the setter and getter method
like
System.out.println(itr.next().getName());
October 19, 2011 at 6:10 PM
Thanks for help i find the solution.
Related Tutorials/Questions & Answers:
class odject in listclass odject in list I have three
class. In first
class i have get and set methods, in second
class i have a
list of objects of first
class then after main
class i want to read the objects values but it will shows only
odject value - Java Beginnersodject value hello friends
i have one doubt on my coding.am... with my out put.
class test
{
public static void main(String ard... i did one change in my program
class test
{
public String toString
Advertisements
List control classList control class Hi...
What
Class does all
list base controls extend? and implement?
please give me the name of these classes.....ADS_TO_REPLACE_1
Tnanks
Ans:
All
list based control extend the ListBase
class PHP list class methods
Function get_
class_methods gives the all methods names of the given
class.
It takes input as
class name and returns the array of the methods name
PHP
LIst Class Methods Example
<?php
class myclass{
function aa
classclass Is a
class a subclass of itself
class is a
class to represent a country in medal tally. It has an attribute of
country...
medals. In this
class, you should also define constructors, and assessor, mutator
methods.
Task 2
MedalTally.java is a
class to model a medal tally, containing
Class Class, Object and Methods
Class : Whatever we can see in this world all
the things... is termed as
a
class. All the
objects are direct interacted with its
class Super class of an Exception classSuper
class of an Exception class hello,,,
What is super
class of an Exception
class?
hii,,ADS_TO_REPLACE_1
the super
class of an exception is throwable
class. and the super
class of an throwable
class ListList i do have one
list object, i want to compare this
list from database table and if match found i want to update the
list ListList getting values from a form and make a
list of them and store them into database
Class
Class
This section explores the concept of
a
class in reference to object oriented programming techniques. A
class defines
the properties of objects and methods used
Java AclNotFoundException Class Hierarchy Diagram Control
List) which
has no existence. Hierarchy of this
class is shown...In this section we will discuss about the
class hierarchy of
AclNotFoundException
Class in Java.
This
class extends the java.lang.Exception
class J2ME List Image with image symbol. In this
example we are trying to create
list using of
List class. The
List class define
in two type of constructors, that is:ADS_TO_REPLACE_1...[] stringElements, Image[]
imageElements)
The
List class has following
class loadersclass loaders
Explain static and dynamic
class loaders
class fileclass file How to create
class file in jsf easily
inner classinner class what is mean by inner
class
Inner
class is a non-static
class which is defined inside another
class Node class Node
class hii,
What is a node
class?
hello,ADS_TO_REPLACE_1
A node
class is a
class that has added new services or functionality beyond the services inherited from its base
class Matrix Class Matrix
Class A
class to manage matrices and add them. Create in the driver
class two objects of it and use the add method
Matrix Class Matrix
Class A
class to manage matrices and add them. Create in the driver
class two objects of it and use the add method
lock on a classlock on a class hello,
Can a lock be acquired on a
class?
hiii,,ADS_TO_REPLACE_1
Yes, a lock can be acquired on a
class. This lock is acquired on the
class's Class object
Java classJava class What is the purpose of the Runtime
class coolection classcoolection class how to find maximum and minimum from a
list using max & min method of collection
class
Here is an example...
class i.e max() and min() respectively.
import java.util.*;
class robot classrobot class please send me uses of robot
class and some examples using robot
class Nested classNested class What is nested
class? when a
class is defined within another
class then such a
class is called a nested
class. Nested... readable and maintainable code.
class OuterClass {
...
static
class class fileclass file how to convert java classfile into java sourcefile
abstract classabstract class Can there be an abstract
class with no abstract methods