???Java 8???????????????????
???????????? ???????[ 2015/9/25 11:42:36 ] ??????????????????? ???????
?????? Java 8 ??????????????????????????????????????Lukas Eder ??????????????????????????????????? Java 8 ??????ABC??????——????????????????????????
??????? Stack Overflow ??????“mip”???????????????????????????????
??????????????????????????????е?????
????A?? B?? C?? ...?? Z?? AA?? AB?? AC?? ...?? ZZ.
??????????????????????? Excel spreadsheet ??????????????????£?
????excel
??????????????????????????? Java 8 ?????????????????????????????????? jOOλ????? Java 8 ?? Stream API ??????????????????????????????——?????л Sebastian ??????????????????
??????????????ú????????????????????????????????У?
????1??????????????????????
????2???????磬????????????????????????????????ZZ?????????2??
????3????????????е??????????????????????????????????cartesian product?????????
?????????????′???
????1???????????
???????????????д?????????磺
????List<String> alphabet = Arrays.asList("A"?? "B"?? ...?? "Z");
??????????????????? jOOλ ???棺
????List<String> alphabet = Seq
????.rangeClosed('A'?? 'Z')
????.map(Object::toString)
????.toList();
???????????????????? A ?? Z ????????Java-8-Stream-speak ???????????????????????????????????????б??
????????????ж???á??????
????2????????磺
??????????????а?????
????A .. Z?? AA?? AB?? .. ZZ
??????????????ú????????????????????????????????У????????
????A .. Z?? AA?? AB?? .. ZZ?? AAA?? AAB?? .. ZZZ
??????????????????? rangeClosed():
????// 1 = A .. Z?? 2 = AA .. ZZ?? 3 = AAA .. ZZZ
????Seq.rangeClosed(1?? 2)
????.flatMap(length -> ...)
????.forEach(System.out::println);
????????????????Χ[1..2]??????????????????????????????????Щ?????????????С?flatMap() ????????????????imperative programming???е????????????
????3??????????????????????
????????????????????????????????????????????????????????μ?????
????Seq.rangeClosed(1?? length - 1)
????.foldLeft(Seq.seq(alphabet)?? (s?? i) ->
????s.crossJoin(Seq.seq(alphabet))
????.map(t -> t.v1 + t.v2))
????);
?????????????? rangeClosed() ???????Χ [1 .. length-1] ?????foldLeft() ?? reduce() ??????£????????? foldLeft() ????????е???????“??????”???????? fold ????????????
??????????棬??????????????????foldLeft() ??????????????????????“???”?????????????????????????????????Seq.seq(alphabet)????????????Χ[1..length-1] ?е??????????????????crossJoin()????????????μ???????????????????????????????????????????????t.v1 ?? t.v2????
?????????????????
??????????????????????
??????????????????? A .. Z?? AA .. ZZ?? AAA .. ZZZ ????????????
import org.jooq.lambda.Seq;
public class Test {
public static void main(String[] args) {
int max = 3;
List<String> alphabet = Seq
.rangeClosed('A'?? 'Z')
.map(Object::toString)
.toList();
Seq.rangeClosed(1?? max)
.flatMap(length ->
Seq.rangeClosed(1?? length - 1)
.foldLeft(Seq.seq(alphabet)?? (s?? i) ->
s.crossJoin(Seq.seq(alphabet))
.map(t -> t.v1 + t.v2)))
.forEach(System.out::println);
}
}
????????
????????????????????????????????Stack Overflow????????????????????????????????
????import static java.lang.Math.*;
????private static String getString(int n) {
????char[] buf = new char[(int) floor(log(25 * (n + 1)) / log(26))];
????for (int i = buf.length - 1; i >= 0; i--) {
????n--;
????buf[i] = (char) ('A' + n % 26);
????n /= 26;
????}
????return new String(buf);
????}
?????????????????????????????????
??????
???·???
??????????????????
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