1. 程式人生 > 其它 >KMP演算法的實現與解析

KMP演算法的實現與解析

技術標籤:java

引用資料型別最大的特點是可以進行記憶體的指向處理 不同方法名描述同一個方法
在這裡插入圖片描述
自有定義:

@FunctionalInterface
public interface Function<T,R>{
    public R apply(T t) ;
}
@FunctionalInterface
public interface Consumer<T>{
    public void accept(T t) ;
}
@FunctionalInterface
public interface Supplier<T>{
    public
T get() ; } //斷言函式式介面 進行判斷處理 equalsIgnareCase() @FunctionalInterface public interface Predicate<T>{ public boolean test(T t) ; }

程式碼:

package com.msc.example;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.
Supplier; interface IFunction<K,R>{ public K change(R r); } interface IFunctionb<R>{ public R upper(); } interface IFunctionc<P>{ public int compare(P p1,P p2); } interface IFunctiond<P>{ public P create(String n,int a); } class Example{ private String name ;
private int age ; public Example(String namr,int age){ this.age = age ; this.name = name ; } @Override public String toString() { return "Example{" + "name='" + name + '\'' + ", age=" + age + '}'; } } public class FunctionDemo { public static void main(String[] args) { IFunction<String,Integer> fun = String :: valueOf; IFunctionb<String> funb = "test" :: toUpperCase; IFunctionc<String> func = String :: compareTo; IFunctiond<Example> fund = Example::new ; String str = fun.change(100) ; System.out.println(str); System.out.println(funb.upper()); System.out.println(func.compare("A","a")); System.out.println(fund.create("里斯",20)); System.out.println("-------------------------------"); Function<String,Boolean> funl = "**hello" :: startsWith; System.out.println(funl.apply("**")); Consumer<String> con = System.out :: println; con.accept("Consumer"); Supplier<String> sup = "com.mSc.cn" :: toLowerCase; System.out.println(sup.get()); Predicate<String> pre = "com" :: equalsIgnoreCase; System.out.println(pre.test("Com")); } }

在這裡插入圖片描述