- package it.harbor.dom4j;
- import java.util.HashSet;
- import java.util.Set;
- public class Demo {
- public static void main(String[] args) {
- Set<String> t = new HashSet<String>();
- t.add("abc");
- t.add("123");
- t.add("heima");
- t.add("a12d");
- // 转化为字符串数组,将该 set 转储到一个新分配的 String 数组:
- String[] str = t.toArray(new String[0]);
- //遍历数组
- for (String string : str) {
- System.out.println(string);
- }
- int temp = 0;
- for (int i = 0; i < str.length; i++) {
- try {
- temp = Integer.valueOf(str[i]);//判断能否转换成数字
- System.out.println(temp);
- } catch (Exception e) {
- System.out.println("Can not be changed to number!");
- }
- }
- }
- }
复制代码 |