Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

String remove duplicate in java

String str1 = "ABCDABCD";
String result1 = "";

for (int a = 0; a <= str1.length()-1; a++) {
if (result1.contains("" + str1.charAt(a))) { 
// charAt methodda you provide index number ve sana character olarak donuyor,
// If the string result does not contains str.CharAt(i), 
// then we concate it to the result. if it does we will not
   continue;
}
result1 += str1.charAt(a);
}
System.out.println(result1);
Comment

remove duplicate value from string

// remove duplicate value from string
let str = "a b a";
let words = str.toLowerCase().split(" ");

const remDuplicate = words.filter((data,index,src)=>{
  return src.indexOf(data)===index
})

console.log("remDuplicate =>",remDuplicate)
Comment

remove duplicate from string

// Java program to create a unique string
import java.util.*;
  
class IndexOf {
      
    // Function to make the string unique
    public static String unique(String s)
    {
        String str = new String();
        int len = s.length();
          
        // loop to traverse the string and
        // check for repeating chars using
        // IndexOf() method in Java
        for (int i = 0; i < len; i++) 
        {
            // character at i'th index of s
            char c = s.charAt(i);
              
            // if c is present in str, it returns
            // the index of c, else it returns -1
            if (str.indexOf(c) < 0)
            {
                // adding c to str if -1 is returned
                str += c;
            }
        }
          
        return str;
    }
  
    // Driver code
    public static void main(String[] args)
    {
        // Input string with repeating chars
        String s = "geeksforgeeks";
          
        System.out.println(unique(s));
    }
}
Comment

remove duplicates from string in java

int i,j;
StringBuffer str=new StringBuffer();
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
str.append(in.nextLine());

for (i=0;i<str.length()-1;i++){
    for (j=i+1;j<str.length();j++){
        if (str.charAt(i)==str.charAt(j))
            str.deleteCharAt(j);
    }
}
System.out.println("Removed non-unique symbols: " + str);
Comment

delete repeated words in string

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main ()
{
	char str[100], word[100], twoD[10][30];
	int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0;
 
	printf ("Enter the string
");
	gets (str);
 
	// let us convert the string into 2D array
	for (i = 0; str[i] != ''; i++)
	{
		if (str[i] == ' ')
		{
			twoD[k][j] = '';
			k ++;
			j = 0;
		}
		else
		{
			twoD[k][j] = str[i];
			j ++;
		}
	}
 
	twoD[k][j] = '';
 
	j = 0;
	for (i = 0; i < k; i++)
	{
		int present = 0;
		for (l = 1; l < k + 1; l++)
		{
			if (twoD[l][j] == '' || l == i)
			{
				continue;
			}
 
			if (strcmp (twoD[i], twoD[l]) == 0) {
				twoD[l][j] = '';
				present = present + 1;
			}
		}
		// if (present > 0)	     | uncomment this `if` block if you
		// {			     | want to remove all the occurrences 
		// 	twoD[i][j] = '';   | of the words including the word
		// }			     | itself.
	}
 
	j = 0;
 
	for (i = 0; i < k + 1; i++)
	{
		if (twoD[i][j] == '')
			continue;
		else
			printf ("%s ", twoD[i]);
	}
 
	printf ("
");
 
	return 0;
}
Comment

String remove duplicate in java

String str1 = "ABCDABCD";
String result1 = "";

for (int a = 0; a <= str1.length()-1; a++) {
if (result1.contains("" + str1.charAt(a))) { 
// charAt methodda you provide index number ve sana character olarak donuyor,
// If the string result does not contains str.CharAt(i), 
// then we concate it to the result. if it does we will not
   continue;
}
result1 += str1.charAt(a);
}
System.out.println(result1);
Comment

remove duplicate value from string

// remove duplicate value from string
let str = "a b a";
let words = str.toLowerCase().split(" ");

const remDuplicate = words.filter((data,index,src)=>{
  return src.indexOf(data)===index
})

console.log("remDuplicate =>",remDuplicate)
Comment

remove duplicate from string

// Java program to create a unique string
import java.util.*;
  
class IndexOf {
      
    // Function to make the string unique
    public static String unique(String s)
    {
        String str = new String();
        int len = s.length();
          
        // loop to traverse the string and
        // check for repeating chars using
        // IndexOf() method in Java
        for (int i = 0; i < len; i++) 
        {
            // character at i'th index of s
            char c = s.charAt(i);
              
            // if c is present in str, it returns
            // the index of c, else it returns -1
            if (str.indexOf(c) < 0)
            {
                // adding c to str if -1 is returned
                str += c;
            }
        }
          
        return str;
    }
  
    // Driver code
    public static void main(String[] args)
    {
        // Input string with repeating chars
        String s = "geeksforgeeks";
          
        System.out.println(unique(s));
    }
}
Comment

remove duplicates from string in java

int i,j;
StringBuffer str=new StringBuffer();
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
str.append(in.nextLine());

for (i=0;i<str.length()-1;i++){
    for (j=i+1;j<str.length();j++){
        if (str.charAt(i)==str.charAt(j))
            str.deleteCharAt(j);
    }
}
System.out.println("Removed non-unique symbols: " + str);
Comment

delete repeated words in string

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main ()
{
	char str[100], word[100], twoD[10][30];
	int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0;
 
	printf ("Enter the string
");
	gets (str);
 
	// let us convert the string into 2D array
	for (i = 0; str[i] != ''; i++)
	{
		if (str[i] == ' ')
		{
			twoD[k][j] = '';
			k ++;
			j = 0;
		}
		else
		{
			twoD[k][j] = str[i];
			j ++;
		}
	}
 
	twoD[k][j] = '';
 
	j = 0;
	for (i = 0; i < k; i++)
	{
		int present = 0;
		for (l = 1; l < k + 1; l++)
		{
			if (twoD[l][j] == '' || l == i)
			{
				continue;
			}
 
			if (strcmp (twoD[i], twoD[l]) == 0) {
				twoD[l][j] = '';
				present = present + 1;
			}
		}
		// if (present > 0)	     | uncomment this `if` block if you
		// {			     | want to remove all the occurrences 
		// 	twoD[i][j] = '';   | of the words including the word
		// }			     | itself.
	}
 
	j = 0;
 
	for (i = 0; i < k + 1; i++)
	{
		if (twoD[i][j] == '')
			continue;
		else
			printf ("%s ", twoD[i]);
	}
 
	printf ("
");
 
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Java :: console java 
Java :: view all certificates from keystore java 
Java :: how to run java in eclipse 
Java :: java mcq 
Java :: get arguments in fragment kotlin 
Java :: basic java programs 
Java :: lambda java 
Java :: copying primitive array to arraylist in java 
Java :: java split string without removing 
Java :: jdk path 
Java :: enum values to string array 
Java :: hashmaps java 
Java :: how to initialize a string in java 
Java :: java how to print out a string in uppercase 
Java :: java system.out.println not working 
Java :: java throws keyword 
Java :: java instantiate a scanner 
Java :: calling this in constructor java 
Java :: can i have both java7 and java 11 in mac 
Java :: how to get index of arraylist in java 
Java :: power-hungry foobar solution in java 
Java :: deserialize list jackson 
Java :: java loops 
Java :: how to convert iso-8859-1 to utf-8 in java 
Java :: java static variable 
Java :: How to implement the A* shortest path algorithm, in Java? 
Java :: System.out.println("j= 6"); 
Java :: comparer deux entiers java 
Java :: how to pass schema name in jdbc url 
Java :: transparent card background android 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =