using list iterator create student details

using list iterator create student details

View Answers

May 4, 2009 at 11:40 AM

Hi Friend,

First of all we would like to tell you that you can not perform comparison on the Class objects therefore for sorting the class Objects we have to first fetch them and then after sorting them according to some specific values we would have to add them into another list to print them.

Here we are sending you a sample code which will describe you how to create Student class and add its properties to the List .

import java.util.*;

class Student{
private int roll;
private String name;
private int marks;

public void setRoll(int roll){
this.roll = roll;
}
public int getRoll(){
return roll;
}

public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}

public void setMarks(int marks){
this.marks = marks;
}
public int getMarks(){
return marks;
}
}

public class SortStudents
{
public static void main(String args[]){
List stu= new ArrayList();
Student st1= new Student();
st1.setRoll(101);
st1.setName("Amit");
st1.setMarks(56);
Student st2= new Student();
st2.setRoll(103);
st2.setName("Anil");
st2.setMarks(66);
Student st3= new Student();
st3.setRoll(103);
st3.setName("Ankit");
st3.setMarks(76);
stu.add(st1);
stu.add(st2);
stu.add(st3);
ListIterator listItr =(ListIterator)stu.listIterator();
while(listItr.hasNext()){
Student stud =(Student)listItr.next();
System.out.print(" "+stud.getRoll());
System.out.print(" "+stud.getName());
System.out.println(" "+stud.getMarks());
}
}
}

Hope that this will help you in solving your problem.

Thanks
RoseIndia Team









Related Tutorials/Questions & Answers:
using list iterator create student details - JavaMail
using list iterator create student details  write a java program to create student class with particulars like name, rno, marks,etc. and print them in ascending order using iterator(list iterator)  Hi Friend, First
How to create a Student data base using Linked List in java
How to create a Student data base using Linked List in java  I want a program by using linked list in java. The data stored must... Record2 sandhya 22 5apr By using linked list I hve
Advertisements
how to develop student details using springs
how to develop student details using springs  how to develop student details using springs
student details
student details  create an application for details of 1st to 5th standard students by using loops and scanner
student details
student details  hi sir/madam i have a doubt in PHP how to insert student details using mysql with php..   Have a look at the following link: PHP Mysql insert
program to create student report using java applet,read the input using text boxesand generate the grades..?
program to create student report using java applet,read the input using text boxesand generate the grades..?   sir plz give me java applet codes for above question
List iterator java example
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 Iterator has methods hasNext() and next() for traversing . Java List Iterator
Write a program to get student details and store in a database
Write a program to get student details and store in a database  Write a program to get student details and store in a database
Java List Iterator
Java List Iterator is an interface in the collection framework.... It has methods hasNext() and next(). Example of Java List Iterator import java.util.*; public class iterator { public static void main(String
ModuleNotFoundError: No module named 'list_iterator'
ModuleNotFoundError: No module named 'list_iterator'  Hi, My... 'list_iterator' How to remove the ModuleNotFoundError: No module named 'list_iterator' error? Thanks   Hi, In your python
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]  Here I am creating one excel template using [Apache POI] in that user can fill data. In that two drop down list are there. Want to create a drop down list that depends
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]  Here I am creating one excel template using [Apache POI] in that user can fill data. In that two drop down list are there. Want to create a drop down list that depends
Java Generic Iterator
Java Generic Iterator is the new feature added to the jdk1.5. It is used.... It is used with classes, methods and interfaces. Java Generics Iterator... class generic { public static void main(String[] args) { ArrayList list
Java For loop Iterator
Iterator can be used with the for loop also. Initialization of the Iterator is done before the for loop. Iterator has boolean value with the hasNext method. So no increment/decrement is required. Java for Loop Iterator
Java Array Iterator with Example
++) { list[i].add(ar[i][j]); } } Iterator it[] = { list[0].iterator(), list[1].iterator(), list[2].iterator(), list[3].iterator() }; for (int k = 0; k... Java Array Iterator is an interface in the collection framework. Java
Iterator Java Sample
Java Sample Iterator interface makes the traversing of the elements easy...() Java Sample Iterator Example import java.util.ArrayList; import... sample { public static void main(String[] args) { List list = new ArrayList
Java List Iterator Example
Java List Iterator Example In Java Collection framework every classes provides... to start the collection. By using this iterator objects you can access each element...("Andrew"); Now call the iterator() method of list and store the result
Java Hashmap Iterator
Java HashMap Iterator is a collection class. It implements the Map interface. It keeps the data in the key and value form. Java HashMap has no iterator.... Set's all elements can be traversed by the Iterator. Java Hashmap Iterator
Java Hashtable Iterator
in the key and value form. Like hasmap, it has no iterator() method. Use the entrySet... be traversed by the Iterator. Java Hashtable Iterator Example import..."); hastab.put("e", "era"); Set s = hastab.entrySet(); Iterator
Iterator Java Order
List collection elements are ordered while set elements are unordered. The iterator() method of the List Interface gives elements in propersequence...(); Iterator setit = set.iterator(); System.out.println("List elemenys
How to Create Student Registration Form with HTML Code?
will learn to create a student registration form using html code in easy steps...How to Create Student Registration Form with HTML Code? At present, the concept of online student registration form has emerged as a great relief
Java Hasnext Iterator
Java HasNext Iterator is the method of the Iterator Interface. It returns... of false vale loop terminates. Java HasNext Iterator Example import...", "april", "may", "june" }; ArrayList list = new ArrayList(); for (String m
Iterator Java While
The Java While loop Iterator is the top tested loop. It is in two forms while(), do while() While loop is mostly used with Iterator compared to for loop Java While Loop Iterator Example import java.util.ArrayList; import
I tried to create a dropdown list using struts2.it is not working.can you find the errors in this code?
I tried to create a dropdown list using struts2.it is not working.can you find the errors in this code?  /jsp code for creating dropdownlist using...;/*form created*/ <p:select name="designation" label="Enter Designation " list
Iterator Java Size
The Java Iterator size() is the method of the collection Interface... in the collection. Java Size Iterator Example import java.util.*; public class size { public static void main(String[] args) { List list = new
how to create using jsp
how to create using jsp  code 1: <%@ page language="java...; <title>Create New Student</title> </head> <body> <form name="create" method="post" action="<
student
student  how do i create a program that writes out the message :Welcome to Kaplan University!"   Hi Friend, Try the following code: class Message { public static void main(String[] args
Student
Student  Sir i want display data for dropdownlistbox from database and selected value from dropdownlistbox matched value display from database in table..(using ajax) and each row have edit and delete buttton,i click edit
create a form using struts
create a form using struts  How can I create a form for inputting text and uploading image using struts
create using jsp
create using jsp  code 1:``<%@ page language="java" contentType..." content="text/html; charset=ISO-8859-1"> <title>Create New Student</title> </head> <body> <form name="create" method="post
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
Java Iterator with Example
Iterator is an interface in the collection framework It traverses through... hasNext() and next(). Java Iterator Example import java.util.*; public class iterator { public static void main(String[] args
Iterator Java Tutorial
methods hasNext() and next(). List, Set interface has iterator() methods . Example of Java Iterator import java.util.*; public class iterator1... Java Iterator is an interface in the collection framework It traverses
Creating List in Java using SWT
Creating List in Java using SWT       This section illustrates you how to create a list of certain items using the Standard Widget Toolkit In this example, we have create a list
upload file and insert other details to database using a single form
upload file and insert other details to database using a single form   hi.. I have problem with uploading a file and insert other user datas together... but my other details seem to be null
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?  HELLO SIR, CAN ANYONE HELP ME OUT HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILES,IF I ENTER 4 EMPLOYEE DETAILS(NAME,ID,SALARY,EMAIL) ALL THE DETAILS OF 4
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
Create Dynamic Table using Hubernate
Create Dynamic Table using Hubernate  Thank's for reading my Post. I...: How to create seperate table for all users they sign up for my web app. i need to create 2 table's 1.User Details - Store user mail address,username
Create HTML page using java
Create HTML page using java   Hi, I need to create an html page to export some information. Currently, by using java, i've exported information to excel. But now, I would like to view it in HTML instead of excel. Is there any
How to Create Instance using PHP
How to Create Instance using PHP  Hi, How to create an instance class in PHP program. Can someone explain or suggest any online reference how to create an Instance class in PHP. Thanks, (adsbygoogle
Create primary key using hibernate
Create primary key using hibernate  How to create primary key using hibernate?   The id element describes the primary key for the persistent class and how the key value is generated. ADS_TO_REPLACE_1   
Create list from array in Java
Create list from array in Java  Hi, I have an array with some data. How to Create list from array in Java? Thanks   Hi, Here is example... this into array: List<String> list = Arrays.asList(names); Thanks
stack using linked list
stack using linked list  how to implement stack using linked list
Write a program using JSP that enables any student to change his/her address.
Write a program using JSP that enables any student to change his/her address.  Write a program using JSP that enables any student to change his/her address
Java Collection iterator with example
The Java Collection Iterator is present at the highest level interface in the Collection framework. Iterator interface has methods for traversing, but Collection doesn't has iterator() method. So create object with reference
Java Next Iterator
Iterator is used by the set, List Interface and its subclasses. Iterator... it should be casted for further use. Example of Java Next Iterator import...[] = { 11, 22, 33, 44, 55, 66, 77, 88, 99 }; ArrayList list = new ArrayList
student database
student database  student records such as fees-school fees, dob,age,if any due.the record stored should be like this record,name,age,dob,fee list or any dues of the student record1 isha 15 20jan record2 spandana 14 4feb record3
Create Histogram using Jfreechart
Create Histogram using Jfreechart In this section, you will learn how to create histogram using jfreechart. To create a Histogram, we have used... of ten randomly generated numbers to the dataset, using the specified number
Create JTree using an Object
Create JTree using an Object       In this section you will learn  to create a JTree using object that works with Hashtable.  Program Description: ADS_TO_REPLACE_1
Create Popup List in SWT
Create Popup List in SWT       In this section, you will learn how to create the popup list. SWT allows to create the popup list by providing the class PopupList of package

Ads