CFW 2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

Working with New collection frame work from "java.util" package..

==========================================

Working with ArrayList


===================
details of ArrayList :
=============
public class java.util.ArrayList<E> extends java.util.AbstractList<E> implements
java.util.List<E>, java.util.RandomAccess, java.lang.Cloneable, java.io.Seriali
zable

ex:
===

import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Scanner;

public class Work_ArrayList {

public static void main(String[] args) {

ArrayList al=new ArrayList();

System.out.println(" before al is :"+al);

// store

al.add(101); //0
al.add("ravi");//1
al.add(10000.00f);//2
al.add("ravi@gmail.com");//3

al.add(102); //4
al.add("rani");//5
al.add(20000.00f);//6
al.add("rani@gmail.com");//7

al.add(101);
al.add("raju");
al.add(30000.00f);
al.add("raju@gmail.com");

System.out.println(" after al is :"+al);

// updations logics.. (add, relplace, delete)...

al.add(5, "uuuuudash");
System.out.println(" after al is :"+al);

al.remove(7);
System.out.println(" after al is :"+al);

// Login App
String id;

Scanner sc=new Scanner(System.in);

System.out.println(" enter id:");


id=sc.next();

if(al.contains(id))
{
System.out.println(" loged sucess");
}
else
{
System.out.println(" FAIL ");
}

// fetching operations..

System.out.println("==============");

ListIterator ll= al.listIterator();

// from lll fetching

for(; ll.hasNext();)
{
System.out.println( ll.next());

System.out.println("==============");

for(; ll.hasPrevious();)
{
System.out.println( ll.previous());

}
}

impnotes:
========
when we are working with Database operation, then should required retriving
operation...

To retrive element, object from CFW, then we have

1 -> public Iterator iterator();


2 -> public ListIterator listIterator();
3 -> public E element(); // for legaccy

from all Collections from java.util..

1 -> public Iterator iterator();


==========================
A. public boolean hasNext();
==============================
it return true.. if the iterator has element, object .. else it return false..

B. public E next();
=============================
it return element, object if the iterator has element, object..

=> according to the above 2 methods... , then using iterator we can fetch
element, object from CFW in only forword direction..

2 -> public ListIterator listIterator();


===========================

A. public boolean hasNext();

B. public E next();

C. public boolean hasPrevious();


================================

it return true.. if the iterator has element, object .. else it return false..
in previous direction

D. public E previous();
=======================
it return element, object if the iterator has element, object.. in previous
direction..

=> according to the above 4 methods... , then using Listiterator we can fetch
element, object from CFW in both forword and previous direction..
=====================================

You might also like