zoukankan      html  css  js  c++  java
  • job

    package com.study.month8.job07.job01;

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;

    /*1.定义一个字符串数组,存入{"张三","李四","王老五","赵老六","迪丽热巴","马尔扎哈"}
    2.使用增强for遍历数组,找出名字为两个字和名字为四个字的人存入集合中.
    3.使用迭代器遍历集合.删除名字中包含马的人.
    4.修改李四的名字为李老四.*/
    public class job01 {
    public static void main(String[] args) {
    String[] str = {"张三", "李四", "王老五", "赵老六", "迪丽热巴", "马尔扎哈"};
    ArrayList<String> arr = new ArrayList<>();
    for (String s : str) {
    if (s.length() == 2 || s.length() == 4) {
    arr.add(s);
    }
    }
    for (int i = 0; i < str.length; i++) {
    System.out.print(str[i] + " ");
    }
    System.out.println();
    System.out.println(arr);
    System.out.println("--------------");
    Iterator<String> ite = arr.iterator();
    for (int i = 0; i < arr.size(); i++) {
    String s = arr.get(i);
    if ("李四".equals(s)) {
    arr.set(i, "李老四");
    }
    }
    System.out.println(arr);
    System.out.println("--------------");

    while (ite.hasNext()) {
    String s = ite.next();
    if (s.contains("马")) {
    System.out.println(s);
    ite.remove();
    }
    }
    System.out.println(arr);
    }


    }
  • 相关阅读:
    jquery内容过滤器
    jquery的each()
    jquery表单过滤器
    jquery评分星星
    UVa 1595 Symmetry (set && math)
    UVa 1592 Database (map)
    Codeforces 886E Maximum Element 组合数学 + dp
    Codeforces 725E Too Much Money (看题解)
    可持久化字典树
    Codeforces 660F Bear and Bowling 4 斜率优化 (看题解)
  • 原文地址:https://www.cnblogs.com/xiaofeiji/p/13451221.html
Copyright © 2011-2022 走看看