Java??????????
???????????? ???????[ 2015/9/28 11:04:24 ] ??????????????????? ???????
????Java ??????????????int??double?? char???????????????????Java?????????????????Object????Java?????л???????????????Integer??Double??Character???????????????????д???μ????
????Character boxed = 'a';
????char unboxed = boxed;
?????????????????????
????Character boxed = Character.valueOf('a');
????char unboxed = boxed.charValue();
?????????Java???????????ζ?????????????????????????????????????????????????????? OptionalInt ?? IntStream ???????????????????????????У????????JVM?????????????????????
???????
???????磬????????????????????????????Levenshtein??????????Щ??????????????????У?
public class Levenshtein{
private final Function> asList;
public Levenshtein(Function> asList) {
this.asList = asList;
}
public int distance(T a?? T b) {
// Wagner-Fischer algorithm?? with two active rows
List aList = asList.apply(a);
List bList = asList.apply(b);
int bSize = bList.size();
int[] row0 = new int[bSize + 1];
int[] row1 = new int[bSize + 1];
for (int i = 0; i row0[i] = i;
}
for (int i = 0; i < bSize; ++i) {
U ua = aList.get(i);
row1[0] = row0[0] + 1;
for (int j = 0; j < bSize; ++j) {
U ub = bList.get(j);
int subCost = row0[j] + (ua.equals(ub) ? 0 : 1);
int delCost = row0[j + 1] + 1;
int insCost = row1[j] + 1;
row1[j + 1] = Math.min(subCost?? Math.min(delCost?? insCost));
}
int[] temp = row0;
row0 = row1;
row1 = temp;
}
return row0[bSize];
}
}
??????????????????????List???????????????????????????????String????????????????String????List?????
????public class StringAsList extends AbstractList{
????private final String str;
????public StringAsList(String str) {
????this.str = str;
????}
????@Override
????public Character get(int index) {
????return str.charAt(index); // Autoboxing! }
????@Override
????public int size() {
????return str.length();
????}
????}
????...
????Levenshteinlev = new Levenshtein<>(StringAsList::new);
????lev.distance("autoboxing is fast"?? "autoboxing is slow"); // 4
????????Java??????????????????List????????????List???????????????Java10?У???????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11