zoukankan      html  css  js  c++  java
  • 基础内容

    1.set集合类型取交集/并集/差集

     1         String[] str1={"a","b","c","d","e"};
     2         String[] str2={"d","e","f","g","h"};
     3 
     4         Set<String> set1 = new HashSet<String>(Arrays.asList(str1));
     5         Set<String> set2 = new HashSet<String>(Arrays.asList(str2));
     6         Set<String> set = new HashSet<String>();
     7         System.out.println("集" + set2);
     8         // 并集
     9         set.addAll(set1);
    10         set.addAll(set2);
    11         System.out.println("并集" + set);
    12 
    13         // 交集
    14         set.clear();
    15         set.addAll(set1);
    16         set.retainAll(set2);
    17         System.out.println("交集" + set);
    18         // 差集
    19         set.clear();
    20         set.addAll(set1);
    21         set.removeAll(set2);
    22         System.out.println("差集" + set);

    2.给字符串中每两位字符加一个空格

    1         String input = "abcdefghijk";
    2         String regex = "(.{2})";
    3         input = input.replaceAll (regex, "$1 ");
    4         System.out.println (input);
  • 相关阅读:
    反射 元类
    多态
    封装
    继承
    面向基础
    包 logging模块 hashlib模块 openpyxl 深浅拷贝
    常用模块
    re模块(正则表达式)
    模块 导入方式 软件开发目录规范
    第 3 章 镜像
  • 原文地址:https://www.cnblogs.com/alice-cj/p/10635057.html
Copyright © 2011-2022 走看看