AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-collection: Difference between next hasNext nextElement and hasmoreElements

Explain the above mention methods with sample code in jdbc.

corejava x 336
collection x 52
Posted On : 2016-09-06 17:04:14.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
266150
up-rate
3
down-rate

Answers


ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next()) {
// retrieve and print the values for the current row
int i = rs.getInt("a");
String s = rs.getString("b");
float f = rs.getFloat("c");
System.out.println("ROW = " + i + " " + s + " " + f);
}

rest methods we use in collection framework in java. to check resultset is empty or not we do like this:
if (!resultSet.isBeforeFirst() ) {
System.out.println("No data");
}


import java.util.*;
public class Performance {
public static void main(String[] args){
Vector v=new Vector();
Object element;
Enumeration enum;
Iterator iter;
long start;

for(int i=0; i<1000000; i++){
v.add("New Element");
}

enum=v.elements();
iter=v.iterator();
//*****CODE BLOCK FOR ITERATOR**********************
start=System.currentTimeMillis();
while(iter.hasNext()){
element=iter.next();
}
System.out.println("Iterator took " + (System.currentTimeMillis()-start));
//*************END OF ITERATOR BLOCK************************

System.gc(); //request to GC to free up some memory
//*************CODE BLOCK FOR ENUMERATION*******************
start=System.currentTimeMillis();
while(enum.hasMoreElements()){
element=enum.nextElement();
}
System.out.println("Enumeration took " + (System.currentTimeMillis()-start));
//************END OF ENUMERATION BLOCK**********************
}
}

Posted On : 2016-09-06 23:05:53
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185319307
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in