Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners class odject in list
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sudhanshu
class odject in list
2 Answer(s)      3 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


Advertisement
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 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
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
List
List  getting values from a form and make a list of them and store them into database
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
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
Create Popup List in SWT
allows to create the popup list by providing the class PopupList of package... list.open(shell.getBounds()) opens the list and get the selected item. The Button class... Create Popup List in SWT     
class
class  Is a class a subclass of itself
linked list
linked list   how to write a program using a linked list... java.util.*; class LinkedListExample { public static void main(String[] args...); System.out.println("Add elements to LinkedList: "); LinkedList<String> list=new
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
List interface
List interface  What is the List interface
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
Linked List
Linked List  public class Computer{ private int computerNumber; private String computerBrand; public Computer(int, String); } public class... in the following logical linked list represents Computer Number. 76(head) 98 54
linked list
linked list  program for single linked list
list boxs
list boxs  i have two list boxes first list box values from database and i want to assign selected options to the second list box using jsp is it possible to do this in jsp
List interface
List interface  Give me some of the real time examples that can be developed based on List and its implemented classes
Linked list
Linked list  what is difference btw linked list in datastructure and linked list in java
List of mobiles
List of mobiles  which mobile phones support j2me
Java list
Java list  What is the difference between a Choice and a List
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
List In Java
class is one of the implementation among most of the implementation of List.... In this example we will create a Java class where I will use the List interface and its implementing class LinkedList. Then we will insert some elements to list
linked list
linked list  Hi i have a problem with linked list ! how and where i can use linked list? please give me some example.   Please visit...://www.roseindia.net/java/beginners/linked-list-demo.shtml
linked list
linked list   how to add student and mark and number from file in linked list and print them also how to make search function plz can help me sooon
linked list
linked list  hi i have basal problem what is the linked list
list and textbox
list and textbox  sir, i want to create a search, where when i type the letters, the words starting with that letters are to be searched and displayed. Also like a list i should navigate and select the appropriate word which
Array List
Array List   Complete the class House and HouseApp below to display class House{ int lotNo; String type; //Bungalow, SemiDetached double price...¦ } public void setPrice(double p) {ΓΆβ?¬Β¦} } public class HouseApp
Advertisements
 

 

 

DMCA.com