FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java_upgrade/src/main/java/lambdas/FileFilterDemo.java at master · sairam-github/java_upgrade · GitHub
sairam-github
/
java_upgrade
Public
forked from
kousen/java_upgrade
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
lambdas
/
FileFilterDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (62 loc) · 2.23 KB
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
lambdas
/
FileFilterDemo.java
Copy path
File metadata and controls
71 lines (62 loc) · 2.23 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package
lambdas
;
import
java
.
io
.
File
;
import
java
.
io
.
FileFilter
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
java
.
util
.
function
.
Consumer
;
import
java
.
util
.
function
.
DoubleSupplier
;
import
java
.
util
.
function
.
Function
;
import
java
.
util
.
logging
.
Logger
;
public
class
FileFilterDemo
{
public
static
void
main
(
String
[]
args
) {
File
srcDir
=
new
File
(
"src/main/java"
);
File
[]
files
=
srcDir
.
listFiles
();
for
(
File
f
:
files
) {
System
.
out
.
println
(
f
);
}
System
.
out
.
println
(
"Using a file filter to return directories only"
);
files
=
srcDir
.
listFiles
(
new
FileFilter
() {
@
Override
public
boolean
accept
(
File
pathname
) {
return
pathname
.
isDirectory
();
}
});
for
(
File
f
:
files
) {
System
.
out
.
println
(
f
);
}
// compiler: what are the listFiles overloads?
// do any take functional interfaces as arguments?
// if so, do any of the single abstract methods match the
// signature of the provided lambda expression?
FileFilter
filter
=
pathname
->
pathname
.
isDirectory
();
files
=
srcDir
.
listFiles
(
filter
);
for
(
File
f
:
files
) {
System
.
out
.
println
(
f
);
}
filter
=
File
::
isDirectory
;
files
=
srcDir
.
listFiles
(
filter
);
for
(
File
f
:
files
) {
System
.
out
.
println
(
f
);
}
Logger
log
=
Logger
.
getLogger
(
FileFilterDemo
.
class
.
getName
());
Consumer
<
String
>
printer
=
x
->
System
.
out
.
println
(
"The value of x is "
+
x
);
Consumer
<
String
>
logger
=
log
::
info
;
Consumer
<
String
>
printAndLog
=
printer
.
andThen
(
logger
);
List
<
String
>
strings
=
new
ArrayList
<>();
strings
.
add
(
"this"
);
strings
.
add
(
"is"
);
strings
.
add
(
"a"
);
strings
.
add
(
"list"
);
strings
.
add
(
"of"
);
strings
.
add
(
"strings"
);
// List.of("this", "is", "a", "list", "of", "strings")
// .forEach(printAndLog);
strings
.
forEach
(
printAndLog
);
DoubleSupplier
random
=
Math
::
random
;
strings
.
stream
()
.
map
(
String
::
length
)
.
forEach
(
System
.
out
::
println
);
}
}
Back
|
FazBrowse Home
|
New Git URL