This article describes the Java implementation method of removing duplicate letters of string. Share it for your reference, as follows:
package demo;public class Ctrl { public static void main(String[] args){ String s = "akkbccccrsa"; System.out.println("Wulin.com test result: "); System.out.print("Original string: "); System.out.println(s); Ctrl sctrl = new Ctrl(); System.out.print("Stand after deduplication: "); System.out.println(s)); } /* * Clear repeated letter algorithm in string*/ String rmRepeated(String s){ int len = s.length(); int k = 0; int count = 0; String str = ""; char[] c = new char[len]; for(int i=0;i<len;i++){ c[i] = s.charAt(i); } for(int i=0;i<len;i++){ k=i+1; while(k<len-count){ if(c[i]==c[k]){ for(int j=k;j<len-1;j++){ c[j] = c[j+1];//Repetition letters appear, and the array is moved forward from the k position} count++;//The number of times the repeated letters appear k--; } k++; } } for(int i=0;i<len-count;i++){ str+=String.valueOf(c[i]); } return str; }}Running results:
PS: This site also has two simple and practical online text repetition tools, which are recommended for everyone to use:
Online Removal Tool:
http://tools.VeVB.COM/code/quchong
Online text repetition tool:
http://tools.VeVB.COM/aideddesign/txt_quchong
For more information about Java related content, please check out the topics of this site: "Summary of Java Character and String Operation Skills", "Summary of Java Array Operation Skills", "Summary of Java Mathematical Operation Skills", "Tutorial on Java Data Structure and Algorithm" and "Summary of Java Operation DOM Node Skills"
I hope this article will be helpful to everyone's Java programming.