美文网首页
字符序列添加数组元素

字符序列添加数组元素

作者: 哈迪斯Java | 来源:发表于2023-04-08 19:38 被阅读0次

import java.util.function.Function;

public class FunctioinDemo {
// 创建Function接口对象,参数类型是Integer[],返回值类型是String
Function<Integer[], String> function = (n) -> {
StringBuilder str = new StringBuilder(); // 创建字符序列
for (Integer num : n) { // 遍历参数数组
str.append(num); // 字符序列添加数组元素
str.append('.'); // 字符序列添加字符'.'
}
str.deleteCharAt(str.length() - 1); // 删除末尾的'.'
return str.toString(); // 返回字符串
};

public static void main(String[] args) {
    Integer[] ip = { 192, 168, 1, 1 }; // 待处理的数组
    FunctioinDemo demo = new FunctioinDemo();
    System.out.println(demo.function.apply(ip)); // 输出处理结果
}

}

相关文章

网友评论

      本文标题:字符序列添加数组元素

      本文链接:https://www.haomeiwen.com/subject/qvvhddtx.html