Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

List Interface and Map Interface

In the previous video we have seen that what are Collections in Java. In this video we are going to see that what is List interface in Java and what is Map interface in Java.

List interface in Java programming is the sub interface of Collection in Java. It contains methods to insert and delete elements in the index bases. It is a factory of List iterator interface. List Iterator interface in Java is used to transverse the element in backward and forward direction.
Example :
import java.util.*;
public class TestList
{
public static void main(String args[])
{
ArrayList al=new ArrayList();
a1.add("Amit"); a1.add("Vijay");
a1.add ("Kumar");
a1.add (1,"Sachin");
System.out.println ("element at 2nd position: "+al.get (2)); ListIterator itr=al.listIterator();
System.out.println("traversing elements in forward direction...");
while (itr. hasNext())
{
System.out.println(itr.next());
}
System.out.println("traversing elements in backward direction..."); while (itr. hasPrevious())
{
System.out.println(itr.previous());
}
} }
Output :
element at 2nd position : Vijay
traversing elements in forward direction...
Amit
Sachin
Vijay
Kumar
traversing elements in backward direction...
Kumar
Vijay
Sachin
Amit

Java programming language uses hash table to store the elements. It extends Abstract class and implements set interface. It contains unique elements only.

List interface in Java programming can contain duplicate elements whereas a set contains unique elements only.
Example :
import java.util.*;
public class Testhash
{
public static void main(String args[])
{
HashSet al=new HashSet();
a1.add("hi");
a1.add ("hello");
a1.add (how");
a1.add ("who");
Iterator itr=al.iterator();
while (itr.hasNext())
{
System.out.println (itr.next ());
}
} }
Output :
hi
how
hello
who

A Map interface in Java contains values on the basis of key ie. Key and Value pair. Each Key and Value pair is known as an Entry. Java Map contains only unique keys.

Map interface in Java is useful if you have to search, update or delete elements on the basis of key.

So, this are List interface in Java programming and Map interface in Java. In our next video we will learn about Entry Interface in Java and Hash Map Class in Java programming language.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere