趣味编程:静夜思(Functional Java版)

云伯寅
2023-12-01
import static fj.Ord.intOrd;
import static fj.data.List.fromString;

public class Jys2 {
	public static void main(String[] args) {		
		String ss = "床前明月光疑是地上霜举头望明月低头思故乡";
		fromString(ss).zipIndex()
		.groupBy(kv -> kv._2() % 5, intOrd)
		.values().foreachDoEffect(vvs -> System.out.println(
			vvs.toStream().map(vv -> vv._1().toString())
			.foldLeft1((acc, s) -> s + "|" + acc)
		));
	}
}

//低|举|疑|床
//头|头|是|前
//思|望|地|明
//故|明|上|月
//乡|月|霜|光
 类似资料: