Substitute Algorithm(替换算法)
生活随笔
收集整理的這篇文章主要介紹了
Substitute Algorithm(替换算法)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
把某個(gè)算法替換成另一個(gè)更清晰的算法
public String foundPerson(String[] people) {for(int i=0; i<people.length; i++) {if (people[i].equals("Don")) {return "Don";}if (people[i].equals("John")) {return "John";}if (people[i].equals("Kent")) {return "Kent";}}return ""; }重構(gòu):將函數(shù)本體替換為另一個(gè)算法
public String foundPerson(String[] people) {List candidates = Arrays.asList(new String[]{"Don", "John", "Kent"});for(int i=0; i<people.length; i++) {if (candidates.contains(people[i])) {return people[i];}}return ""; }總結(jié)
以上是生活随笔為你收集整理的Substitute Algorithm(替换算法)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsp 页面获取action 属性的方法
- 下一篇: Java并发编程实战~原子类