FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
core-java-concepts/lambda-expression-examples/src/Main.java at main · basecs101/core-java-concepts · GitHub
basecs101
/
core-java-concepts
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
core-java-concepts
/
lambda-expression-examples
/
src
/
Main.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (44 loc) · 1.45 KB
Breadcrumbs
core-java-concepts
/
lambda-expression-examples
/
src
/
Main.java
Copy path
File metadata and controls
53 lines (44 loc) · 1.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
/**
* Functional Interface
*/
interface
FuncInterfaceExample
{
int
display
(
int
a
);
}
/**
* Class implementing functional interface
*/
//class TestClass implements Test {
// @Override
// public int display(int a) {
// return a*a;
// }
//} //similar overridden method written as lambda expression
/**
* Driver class for above functional interface
*/
public
class
Main
{
public
static
void
main
(
String
[]
args
) {
//FuncInterfaceExample test = a -> a*a;
//Lambda expression can be used for providing
//method implementation for functional interface.
FuncInterfaceExample
funcInterfaceExample
=
a
-> {
System
.
out
.
println
(
"Inside Display method"
);
return
a
*
a
;
};
//this is implementations of display method.
int
result
=
funcInterfaceExample
.
display
(
10
);
System
.
out
.
println
(
"Result from display method : "
+
result
);
//Another example for lambda expression
List
<
String
>
guestList
=
new
ArrayList
<>();
guestList
.
add
(
"Vikram"
);
guestList
.
add
(
"Vivek"
);
guestList
.
add
(
"Sam"
);
//Print all elements of guestList using for loop
for
(
String
guestName
:
guestList
){
System
.
out
.
println
(
guestName
);
}
//Print all elements of guestList using forEach loop and Lambda exp
guestList
.
forEach
(
guestName
->
System
.
out
.
println
(
guestName
));
}
}
Back
|
FazBrowse Home
|
New Git URL