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



Home Answers Viewqa Java-Beginners class odject in list

Have Programming Question? Ask it here!
 
 
 


sudhanshu
class odject in list
2 Answer(s)      2 years and 9 months 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
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
List interface
List interface  What is the List interface
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
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 of mobiles
List of mobiles  which mobile phones support j2me
Java list
Java list  What is the difference between a Choice and a List
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
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
wrapper class
wrapper class  list wrapper class methods
linked list
program to manage the registration details for the institute. 1. Use a linked list to manage the details of all registered students. a. Create your own linked list
DropDown list
DropDown list  how to get mysql database values into dropdown usign java servlet and ajax?   Here is a jsp code that displays the database values into dropdown list. 1)country.jsp: <%@page import="java.sql.*"%>
Array List
to hear ideas or answers from everyone. The situation: Complete the class House and HouseApp below to display class House{ int lotNo; String type... thePrice() { ? } public void setPrice(double p) {?} } public class
list - Java Interview Questions
*; class ListExample { public static void main(String[] args) { List...list  Hi all Naturally in java a list will allow duplicates, but if i want the list which shouldn't allow duplicates then what should be the logic
list to be displayed in jsp page.
list to be displayed in jsp page.  Can any one help me? Am developing the code in struts.I have a list in action class that has to be printed in the dropdownlist in another jsp page.Please help me in the code.. Thank u
pdf list
pdf list       In this program we are going to know how we can make a list in a pdf file irrespective... is going to perform. Inside the class declare a main method inside which we
PHP list all variables
PHP all declared and environment variables can be listed get_defined_vars() method returns all the variables in the form of array. The array returned is handles by the class ArrayObject class. Example of PHP List of all
struts dropdown list
); **DAO Class:-** public static ArrayList<DropDownVO> getValues(String list...struts dropdown list   In strtus how to set the dropdown list values... Class:-** ArrayList<DropDownVO> masterList = null; masterList
JSP List Size
of countries using the class List and ArrayList. The method l.size() of class List... JSP List Size          JSP List Size is used to get the size
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
about linked list
in linked list   import java.util.*; class StudentData{ int id...about linked list   hey can u help me soon ?? i want to add student...; LinkedList<StudentData> list=new LinkedList<StudentData>(); Scanner
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List  ...*; import java.awt.event.*; public class CheckBoxInList{ public static void...(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(new
array list example
array list example  Array list example   Hello Friend, Please visit the following links: Array List Example1 Array List Example2 Thanks
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
multiple selections list in Struts
multiple selections list in Struts  How to create a multiple selections list in Struts? and retrive seleted values
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
Advertisements
 

 

 

DMCA.com