Practical 2
Practical 2
A) LIST INTERFACE:
THEORY:
The List interface provides a way to store the ordered collection. It is a
child interface of Collection. It is an ordered collection of objects in
which duplicate values can be stored. Since List preserves the insertion
order, it allows positional access and insertion of elements.
package something;
import java.util.*;
class BoundedShape
{
static Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
int inp = sc.nextInt();
nums.add(inp);
}
Iterator<Integer> it = nums.iterator();
System.out.println("ARRAY IS\n");
while(it.hasNext()) {
System.out.println(it.next());
}
System.out.println(' ');
}
public static void main(String args[])
{
System.out.println(' ');
al();
}
}
OUTPUT:
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
CONCLUSION:
Hence list interface Implemented successfully
package something;
import java.util.*;
class BoundedShape
{
static Scanner sc = new Scanner(System.in);
static void ll()
{
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
String inp = sc.next();
li.add(inp);
}
System.out.println("LINK LIST IS\n");
for(String i:li)
{
System.out.println(i);
}
System.out.println(' ');
}
OUTPUT:
package something;
import java.util.*;
class employee {
int id;
String name;
Double sal;
System.out.print("ID : ");
int id1=sc.nextInt();
System.out.print("NAME : ");
String name1=sc.next();
System.out.print("SALARY : ");
Double salary1=sc.nextDouble();
OUTPUT:
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
o CONCLUION:
Hence list interface Implemented successfully.
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
B) SET INTERFACE:
THEORY:
A Set is a Collection that cannot contain duplicate elements. It models
the mathematical set abstraction.The Set interface contains only
methods inherited from Collection and adds the restriction that duplicate
elements are prohibited.
CODE:
package something;
import java.util.*;
System.out.println("\n");
System.out.println("\n");
OUTPUT:
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
CONCLUSION:
Hence set interface Implemented successfully
C) MAP INTERFACE:
THEORY:
The Map interface maps unique keys to values. A key is an object that you
use to retrieve a value at a later date.Given a key and a value, you can
store the value in a Map object. After the value is stored, you can retrieve
it by using its key.
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
package something;
import java.util.*;
CONCLUSION:
Hence map interface Implemented successfully
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
D) LAMBDA EXPRESSION:
THEORY:
Lambda Expressions were added in Java 8.A lambda expression is a
short block of code which takes in parameters and returns a value.
Lambda expressions are similar to methods, but they do not need a
name and they can be implemented right in the body of a method.
package something;
interface ftoc
{
public int convert(int c);
}
OUTPUT:
2) Kilometers to miles:
CODE:
package something;
interface ktom
{
public double travel(double c);
}
OUTPUT:
ATHARVA KALE PRACTICAL 2 ROLL NO: 27
CONCLUSION:
Hence lambda expressions Implemented successfully.