List manipulation in java (add,delete,view,modify)
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra âMentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
5. Muhammed Noufal V T
muhammednoufalvt@gmail.c
om
www.facebook.com/vtnoufa
lvt
twitter.com/noufalurnappy
in.linkedin.com/pub/muham
med-noufal
9744003056
6. 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
7. 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 ( );
8. 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
9. List Operations
⢠Add
â Syntax
List name.add(item name);
⢠Delete
â Syntax
List name.remove(item name);
⢠Display
â Syntax
List name.get(item name);
11. 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;
}
12. 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;
}
16. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 â 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 â 495 40 25 550
Editor's Notes
Open EmployeeBean.java fileRight click inside the file select Source->Generate Getters and Setters