Question: collections



Share on Google+Share on Google+

Manoj Hunasigi
1 Answer(s)      6 years and a month ago
Posted in : Java Beginners

please explain me the flow of this prog

import java.util.*;

public class listinterface {

 * @param args
public static void main(String as[]) {
    ArrayList al= new ArrayList();
    al.add(new Integer(99));
    al.add("[email protected]");
    List list=al.subList(1,4);
    System.out.println("forward order");
    ListIterator li= al.listIterator();
    System.out.println("reverse order");



View Answers

April 19, 2011 at 1:15 PM

In the given code, an object of ArrayList is created. The method add() then adds an integer value and four string values to the array list. And then System.out.println(al) displays the array list values. The method al.add(0,"aaaa") adds an element "aaaa" at the postion 0 to the list and the al.add(2,"bbbb") adds the element "bbbb" at the position 2 to the list. The method remove(4) removes the element specified at position 4 from the list. The method get(2) displays the element of the list whose position is 2. As there is no element "Sri" so the method indexOf("Sri") returns -1. The method lastIndexOf("Sri") returns the last occurring index of the element from the list. The method set(0,"jlc") replaces the element specified at the postion 0 with the "jlc". The ListIterator is an iterator for lists that allows the programmer to traverse the list in either direction. The method next() returns the next element in the list or you can say display the list of elements in forward direction. The method previous() of this class returns the previous element in the list or you can say in backward direction.


Related Tutorials/Questions & Answers:
Collections  Hi, Please send a study material on collections.../java/jdk6/introduction-collections-api.shtml
collections  why we need collections.when we will use collections in our applications
collections  in collections can we perform binarysearch on arraylist elements without sorting them
what is collections?
what is collections?  what is collections
Collections API
Collections API  hello, What is the Collections API?   hi The Collections API is a set of classes and interfaces that support operations on collections of objects
Collections in Java
Collections in Java  What is Concurrent Hash map
Collections in Java
Collections in Java  What is Concurrent Hash map
java collections
java collections  what are all the methods and things added for collections in java5 and java6 please kindly reply me as soon as possible
Collections Framework
Collections Framework  Sir, We know that both HashMap & Hashtable is using for same purposes i.e Used for storing keys-values pair. But there is some difference between this two class that are 1)Hashtable is synchronized
collections in java
collections in java  please explain me the flow of this program..i m getting o/p as 2 1 1..y not 2 1 it that if we change the i2 value,it doesnt remove. import java.util.*; public class Mapit { public static void main
java collections
achieve this plz without using stringtokenizer with any collections!!!  
Hibernate Criteria With Collections Example
Hibernate Criteria With Collections Example  Good code of Hibernate Criteria With Collections Example. Thanks   Example program of using Hibernate Criteria With Collections in your Java project. Check the tutorial
collections - Java Interview Questions
collections   what is the way to insert map values into a set in collections
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?


Advertisement null