📌  相关文章
📜  如何从java代码示例中的char数组中删除重复元素

📅  最后修改于: 2022-03-11 14:52:08.395000             🧑  作者: Mango

代码示例1
public static void main(String[] args) {
    Main main = new Main();
    char[] array = {'e','a','b','a','c','d','b','d','c','e'};
    main.getCharArray(array);
}

private char[] getCharArray(char[] array) {
    String _array = "";
    for(int i = 0; i < array.length; i++) {
        if(_array.indexOf(array[i]) == -1) // check if a char already exist, if not exist then return -1
            _array = _array+array[i];      // add new char
    }
    return _array.toCharArray();
}