13- The Predicate Interface
Jul 01, 2026 03:38
· 2:02
· English
· Whisper Turbo
· 2 Konekte
Transkript sa a ekspire jodi a.
Ajoutè pou depo perpétuel →
Montre sèlman
0:03
S…
Speaker 1 (13- The Predicate Interface)
Another type of functional interface we have in Java is the predicate interface,
0:07
S…
Speaker 1 (13- The Predicate Interface)
which is extremely useful.
0:08
S…
Speaker 1 (13- The Predicate Interface)
It has tons of applications in the real world.
0:11
S…
Speaker 1 (13- The Predicate Interface)
We use this interface to filter data.
0:13
S…
Speaker 1 (13- The Predicate Interface)
I will show you how to do that in the next section.
0:15
S…
Speaker 1 (13- The Predicate Interface)
So over here,
0:17
S…
Speaker 1 (13- The Predicate Interface)
you can see that this interface has a single abstract method
0:21
S…
Speaker 1 (13- The Predicate Interface)
called test.
0:22
S…
Speaker 1 (13- The Predicate Interface)
We give it an object of type T and get a boolean.
0:26
S…
Speaker 1 (13- The Predicate Interface)
So with this method,
0:27
S…
Speaker 1 (13- The Predicate Interface)
we can check to see if this object satisfies some criteria.
0:30
S…
Speaker 1 (13- The Predicate Interface)
For example,
0:31
S…
Speaker 1 (13- The Predicate Interface)
we can give it a customer object and check to see if that customer has a balance.
0:35
S…
Speaker 1 (13- The Predicate Interface)
This is how we use this interface for filtering data.
0:38
S…
Speaker 1 (13- The Predicate Interface)
Now,
0:39
S…
Speaker 1 (13- The Predicate Interface)
just like the other interfaces,
0:40
S…
Speaker 1 (13- The Predicate Interface)
we have a few specializations of this interface.
0:42
S…
Speaker 1 (13- The Predicate Interface)
For example,
0:43
S…
Speaker 1 (13- The Predicate Interface)
we have by predicate which takes two arguments and returns a
0:48
S…
Speaker 1 (13- The Predicate Interface)
boolean.
0:48
S…
Speaker 2 (13- The Predicate Interface)
Take a look.
0:50
S…
Speaker 1 (13- The Predicate Interface)
So, here's a test method,
0:51
S…
Speaker 1 (13- The Predicate Interface)
it has two arguments of type T and U,
0:54
S…
Speaker 1 (13- The Predicate Interface)
and it returns a boolean.
0:56
S…
Speaker 1 (13- The Predicate Interface)
We also have primitive specializations of this interface.
0:59
S…
Speaker 1 (13- The Predicate Interface)
For example,
1:00
S…
Speaker 1 (13- The Predicate Interface)
we have int predicate,
1:01
S…
Speaker 1 (13- The Predicate Interface)
which takes a primitive integer and returns a boolean.
1:05
S…
Speaker 1 (13- The Predicate Interface)
We also have long predicate and double predicate.
1:08
S…
Speaker 1 (13- The Predicate Interface)
Now let me show you how to work with the predicate interface in Java.
1:12
S…
Speaker 1 (13- The Predicate Interface)
Let's say we have a string like sky,
1:15
S…
Speaker 1 (13- The Predicate Interface)
and we want to check to see if this string has more than five characters.
1:19
S…
Speaker 1 (13- The Predicate Interface)
So we declare a predicate of string call
1:23
S…
Speaker 1 (13- The Predicate Interface)
it is longer than five and send it
1:27
S…
Speaker 1 (13- The Predicate Interface)
to a lambda expression like this str goes to str
1:31
S…
Speaker 1 (13- The Predicate Interface)
.length is greater than five.
1:34
S…
Speaker 2 (13- The Predicate Interface)
Once again,
1:35
S…
Speaker 1 (13- The Predicate Interface)
we don't have a return keyword.
1:36
S…
Speaker 1 (13- The Predicate Interface)
We don't have curly braces either.
1:37
S…
Speaker 1 (13- The Predicate Interface)
All we have is a boolean expression because we should return a
1:42
S…
Speaker 1 (13- The Predicate Interface)
boolean value.
1:43
S…
Speaker 1 (13- The Predicate Interface)
Now to use this predicate we call is
1:47
S…
Speaker 1 (13- The Predicate Interface)
longer than five dot test.
1:50
S…
Speaker 1 (13- The Predicate Interface)
We give it our input like sky and then get the result.
1:53
S…
Speaker 2 (13- The Predicate Interface)
Next,
1:55
S…
Speaker 1 (13- The Predicate Interface)
I'm going to show you how to combine predicates to build more complex predicates.
Transkript sa a te kreye pa AI (automatic speech recognition). Li ka gen erè — tcheke ak son orijinal la pou itilize kritik. Politik AI
Resume
Klike sou Remak pou kreye yon remak AI de transkript sa a.
Enstale...
Konbyen tan pou m' fè transkript la?
Mande nenpòt bagay sou transkript sa a - AI a pral jwenn seksyon ki enpòtan yo epi reponn.