- package com.heima.mianshi;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.util.ListIterator;
- public class Test2 {
- /**
- 将List集合下包含数字的元素去掉
- */
- public static void main(String[] args) {
- List<String> li = new ArrayList<String>();
- li.add("abd4");
- li.add("ab54hdo");
- li.add("abd");
- System.out.println(li);
- /*ListIterator<String> lit = li.listIterator();
- while (lit.hasNext()) {
- String str = (String) lit.next();
- char[] charArray = str.toCharArray();
- for (char c : charArray) {
- if (c>='0'&&c<='9') {
- lit.remove();
- }
- }*/
-
- Iterator<String> it = li.iterator();
- while (it.hasNext()) {
- String str = (String) it.next();
- String Regex = "\\d";
- if (str.contains(Regex)) {
- it.remove();
- }
- }
-
- System.out.println(li);
- }
- }
复制代码 |
|