Experiment 14 22z433
Experiment 14 22z433
Roll No : 22Z433
Date : 08/12/2023
Experiment 14
1.
Aim : To write a java program to add two numbers using Lambda
expression.
package EXP_14;
// Functional interface
interface Addable{
int sum(int a, int b);
}
}
}
santhoshtk@intense ~/Desktop/PSG-TECH/3rd-sem/OPP-LAB
Sum of two numbers is : 30
Name : T K Santhosh
Roll No : 22Z433
Date : 08/12/2023
2.
Aim : To write a java program to use the lambda expression to sort a list of
strings.
import java.util.ArrayList;
import java.util.Collections;
// Functional interface.
interface SortStrings{
void sort_string(ArrayList<String> values);
}
santhoshtk@intense ~/Desktop/PSG-TECH/3rd-sem/OPP-LAB
Sorted values : [blue, green, red]
Name : T K Santhosh
Roll No : 22Z433
Date : 08/12/2023
3.
Aim : To write a java program to concatenate two strings using lambda
expression.
package EXP_14;
// Functional interface
interface ConcatenatingString{
String concat(String a, String b);
}
System.out.println(cs.concat(x, y));
System.out.println(cs.concat("hello,", "world"));
}
}
santhoshtk@intense ~/Desktop/PSG-TECH/3rd-sem/OPP-LAB
santhosh tk
hello,world
4.
Aim : To write a java program to find maximum and minimum element in a
list using lambda expression.
// Program to find maximum and minimum element in a list using
lambda expression.
Name : T K Santhosh
Roll No : 22Z433
Date : 08/12/2023
package EXP_14;
import java.util.ArrayList;
import java.util.Collections;
// Functional interface
interface FindMinMax{
ArrayList <Integer> find_min_max(ArrayList <Integer>
values);
}
return outputs;
};
}
}
santhoshtk@intense ~/Desktop/PSG-TECH/3rd-sem/OPP-LAB
Minimum and maximum element in the array are : [10, 40]
Name : T K Santhosh
Roll No : 22Z433
Date : 08/12/2023
5.
Aim : To write a java program to find the sum of squares of all odd and
even numbers.
package EXP_14;
import java.util.ArrayList;
interface OddEvenSquares{
ArrayList <Integer> odd_even_square_sum(ArrayList
<Integer> values);
}
output.add(odd);
output.add(even);
return output;
};
santhoshtk@intense ~/Desktop/PSG-TECH/3rd-sem/OPP-LAB
Sum of squares of odd and even numbers are : [10, 20]
Result
Hence the given programs were executed successfully.