Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to remove duplicate elements from char array in java

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();
}
Comment

PREVIOUS NEXT
Code Example
Java :: java date minus 1 day 
Java :: str.substring last 2 java 
Java :: string vs stringbuffer 
Java :: jpa enum as string 
Java :: Right triangle star pattern in java 
Java :: how to check the current user in firebase android 
Java :: how to convert a number into a decimal number in java 
Java :: java loop through list 
Java :: java read next line 
Java :: remove first and last character from string in java 
Java :: playerhead command minecraft 
Java :: random boolean java 
Java :: count occurrences of character in string java 8 
Java :: android application class manifest 
Java :: java error message 
Java :: No Java files found that extend CordovaActivity. [ERROR] An error occurred while running subprocess cordova. 
Java :: android:windowLightStatusBar programmatically 
Java :: java string to number 
Java :: java iterator to stream 
Java :: worldedit api paste schematic 
Java :: java generate uuid 
Java :: java how to define a function 
Java :: java for loop increment by 3 
Java :: is palindrome java 
Java :: initialize hashmap with values 
Java :: java reverse string 
Java :: java class jar determine 
Java :: java instanceof keyword 
Java :: default parameters in java 
Java :: how to create alert dialog in android studio 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =