Home Answers Viewqa Java-Beginners class odject in list

 
 


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

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 Pages:
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
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
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
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
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
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
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
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
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
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
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
wrapper class
wrapper class  list wrapper class methods
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
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
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
List
List  getting values from a form and make a list of them and store them into database
Dependent drop down list
dependent drop down list is used my code is successful but when i select class from first drop down list all the data get lossed means the value entered in fields before drop down list get blank.what can i do for this? This is the code
List in J2ME
List in J2ME       J2ME Canvas List Example will explain you, how to create list of items. In this example we are going to create a simple list of text, that will show
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     
Converting java arrays into list
Arrays can be converted by the asList() method of the Arrays class. asList() It converts the object array into the fixed sized list Example import java.util.*; public class array4 { public static void main(String[] args
List iterator java example
Example import java.util.*;public class list { public static void main(String... Java List Iterator is an interface in the collection framework. List is an interface. Its all elements can be traversed by the Iterator. Java List
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
Circular Array List - java tutorials
class CircularArrayList extends AbstractList implements List, Serializable...Circular Array List 2001-08-02 The Java Specialists' Newsletter [Issue 027] - Circular Array List Author: Dr. Heinz M. Kabutz If you are reading
Java file list()
of the given directory. list(): This method of Files class returns an array of strings...Java file list() This section demonstrates you the use of method list(). You can get the list of files and directories in two ways. Either by using
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
capacity of list - Java Interview Questions
class ListCapacity{ public static void main(String args[]){ List list = new...capacity of list  How to find the capacity of list. is there any method to find capacity of list like vector.capacity(); Thanks   Hi
linked list in java - Java Beginners
linked list in java  Hi, how to implement linked list in java using... java.util.*; public class LinkedListExample { static final int N = 10000; static List values; static { Integer vals[] = new Integer[N]; Random rn = new
list files only - Java Beginners
list files only  i have to list only files and number of files in a directory? i use list() method but it returns both files and directories... java.io.*; public class CreateFile{ public static void main(String[] args
Simple Linked List Exercise 1
Java Notes: Simple Linked List Exercise 1 Name... and puts them in a doubly linked list. 1 2 3 4 5 6 7 8... 41 42 43 44 45 import java.util.Scanner; public class
awt list item* - Swing AWT
awt list item*  how do i make an item inside my listitem...*; public class ChoiceListDemo{ public static void main(String[] args) { Frame frame=new Frame("Add list"); Label label=new Label("What is your Choice
Persist a List Object in Hibernate - Hibernate
Persist a List Object in Hibernate   Hi All, I have a query on hibernate. How to persist a List object in Hibernate ? Can you give me... org.hibernate.criterion.Projections; public class projectionExample
list file number - Java Beginners
list file number  sir you still haven't understand my problem. i have to list out only the number of files in a given directory,your solution still... java.io.*; public class CreateFile{ public static void main(String
Spring List Elements Example
Spring <list> Configuration Element This list element is used to store... can be used to set values to the list. <value> element can be used to set... value. Lets take an example to demonstrate how list element is used
How to use List in velocity
How to use List in velocity       This Example shows you how to use List in velocity. ... of VelocityContext Class. 3:- Create Template class object, Template  class object
Shuffling the Element of a List or Array
are explained below which have been used in the program:  List: This is the class... class. It constructs an empty list. You can specify the capacity of the list... of the Collections class which is used to sort the list elements in the default order. Here
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using... javax.swing.event.*; public class SingleList extends JPanel implements ListSelectionListener { private JList list; private DefaultListModel listModel
Spring List Factory
. The SetTargetListClass method set the class to use target List. Week.java package...Spring List Factory Ths ListFactoryBean is a simple factory for shared List instance. The list element is defined in the xml bean definitions
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class suppose class a the corresponding section dropdown list should retrieve the section
how to send email list of email address through in database table list
how to send email list of email address through in database table list  package com.com; import java.io.IOException; import java.io.PrintWriter... com.mysql.jdbc.Statement; public class SendMail extends HttpServlet { public void doGet
Java list directories
used the methods of File class to retrieve the list of directories from the particular directory. In the given example, we have created an object of File class...Java list directories In this section, you will learn how to display the list
Java list files
Java list files In this section, you will learn how to display the list... have created an object of File class and parse the directory through the constructor of the File class. Then we have called listFiles() method which actually
Hibernate Criteria Unique List
Hibernate Criteria Unique List An example of hibernate criteria unique list is given below, which returns the unique value in list from a table...; public class CriteriaUniqueList { public static void main(String[] args
List of all Locales
.style1 { color: #FFFFFF; } List of all Locales...; This Example shows you list of locales. In the code given below we are showing you list... : SimpleDateFormat.getAvailableLocales() : SimpleDateFormat class is using for format
Generate shuffling in the specified list
java.util.List; import java.util.Random; public class ListShuffling{ public static...", "Komal"}; // create list for the specified array of employee. List list1 = Arrays.asList(employee); // create object of Random class

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.