List manipulation in java (add,delete,view,modify)

Post on 26-May-2015

585 views 0 download

Tags:

description

List manipulation in java (add,delete,view,modify)

Transcript of List manipulation in java (add,delete,view,modify)

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Week Target Achieved

1 40 24

2 40 28

3 40 29

Typing Speed

Jobs AppliedWeek Company Designation Applied Date Current Status

1 Career port Programmer 6-10-2013 Waiting

2 Poornam info tech

Software Engineer 30-9-2013 Waiting

3

List manipulation in JAVA

Muhammed Noufal V Tmuhammednoufalvt@gmail.co

mwww.facebook.com/vtnoufalvttwitter.com/noufalurnappyin.linkedin.com/pub/

muhammed-noufal9744003056

Kinds of Collections• Collection—a group of objects,

called elements– Set—An unordered collection with no

duplicates

–SortedSet—An ordered collection with no duplicates–List—an ordered collection,

duplicates are allowed

List implementation

• List is an interface; you can’t say new List ( )

• There are two implementations:–LinkedList gives faster insertions and

deletions–ArrayList gives faster random access

• Syntax:-–List list = new LinkedList ( );–List list = new ArrayList ( );

Type Of List

• ArrayList– Array lists are created with an initial

size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk.

• LinkedList– LinkedList uses nodes to hold the

elements. These nodes then point to each other, thus leading to the name "Linked" List

List Operations

• Add– Syntax

List name.add(item name);

• Delete– Syntax

List name.remove(item name);

• Display– Syntax

List name.get(item name);

Example

Add Operation

public class Add {

static ArrayList <Listbean> data = new ArrayList<Listbean>();int adddata(){Listbean lb =new Listbean();Scanner li = new Scanner(System.in);System.out.println("Enter your Item");lb.setItem(li.next());System.out.println("Enter your price");lb.setPrice(li.next());data.add(lb);return 0;}

Delete Operation

• int remvdata(){System.out.println("Enter the position of item You want to remove: "); Scanner rmv = new Scanner(System.in); int x = rmv.nextInt(); data.remove(x); return 0;}

Display Operation• int dispdata()

{if(data.isEmpty())System.out.println("The Array is Empty");elseSystem.out.println("The Array Elements are: ");for(int i=0;i< data.size();i++){Listbean beanObj=(Listbean) data.get(i);System.out.print(beanObj.getItem());

System.out.println("\t"+beanObj.getPrice()); } return 0;}

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Start up VillageEranakulam,Kerala, India.

Email: info@baabtra.com