String数组排序去重

    xiaoxiao2022-07-04  132

    利用TreeSet实现,

    public class TestArray { public static void main(String[] args) { String[] a = { "a", "cb", "c", "a", "ab" }; TreeSet<String> vinFlag = new TreeSet<String>(); for (String s : a) { vinFlag.add(s); } for (String s : vinFlag) { System.out.print(" " + s); } } }

    执行效果如下:

    最新回复(0)