class odject in list

Ads

 
 

Share on Google+Share on Google+

sudhanshu
class odject in list
2 Answer(s)      6 years ago
Posted in : Java Beginners

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

Ads
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.


Ads









Related Tutorials/Questions & Answers:
class odject in list
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
odject value - Java Beginners
odject 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 class
List control class  Hi... What Class does all list base controls extend? and implement? please give me the name of these classes..... Tnanks   Ans: All list based control extend the ListBase class and implement
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
class
class  Is a class a subclass of itself
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
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
Version of com.fommil>class-monkey dependency
List of Version of com.fommil>class-monkey dependency
List
List  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
wrapper class
wrapper class  list wrapper class methods
List
List  getting values from a form and make a list of them and store them into database
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
Version of com.julianpeeters>case-class-generator_2.10 dependency
List of Version of com.julianpeeters>case-class-generator_2.10 dependency
Version of com.julianpeeters>case-class-generator_2.11 dependency
List of Version of com.julianpeeters>case-class-generator_2.11 dependency
Version of com.kreattiewe>case-class-mapper_2.11 dependency
List of Version of com.kreattiewe>case-class-mapper_2.11 dependency
Version of com.larrymite>js-class-loader-parent dependency
List of Version of com.larrymite>js-class-loader-parent dependency
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
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: List(String..., Image[] imageElements)  The List class has following Methods: append
coolection class
coolection 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
Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho
Given a list of methods for a stateful or stateless session bean class...;Next     Given a list of methods for a stateful or stateless session bean class, define which of the following operations can
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
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
.class and .tld
.class and .tld  how to create .class and .tld file
class loaders
class loaders   Explain static and dynamic class loaders
class file
class file  How to create class file in jsf easily
inner class
inner 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, A node class is a class that has added new services or functionality beyond the services inherited from its base class

Ads

 
Advertisement null

Ads