Java String Repeat deleteRepeatStr(String repeatStr, String separator)

Here you can find the source of deleteRepeatStr(String repeatStr, String separator)

Description

delete this repeat character

License

Open Source License

Parameter

Parameter Description
repeatStr The String contain the repeat character
separator The list separator

Return

noRepeatStr The String has not contain the repeat character

Declaration

public static String deleteRepeatStr(String repeatStr, String separator) 

Method Source Code

//package com.java2s;
/*//from  w ww.ja  v  a2  s.  c  om
* @(#)Utility.java
*
* Copyright (c) 2003 DCIVision Ltd
* All rights reserved.
*
* This software is the confidential and proprietary information of DCIVision
* Ltd ("Confidential Information").  You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with DCIVision Ltd.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * delete this repeat character
     * @param repeatStr The String contain the repeat character
     * @param separator The list separator
     * @return noRepeatStr The String has not contain the repeat character
     */
    public static String deleteRepeatStr(String repeatStr, String separator) {
        if (repeatStr == null) {
            return null;
        }
        StringBuffer noRepeatStr = new StringBuffer();
        String[] strElement = repeatStr.split(separator);
        List strlist = new ArrayList();
        for (int i = 0; i < strElement.length; i++) {
            if (!strlist.contains(strElement[i])) {
                strlist.add(strElement[i]);
            }
        }
        for (int i = 0; i < strlist.size(); i++) {
            noRepeatStr.append(strlist.get(i));
            if (i != strlist.size() - 1) {
                noRepeatStr.append(separator);
            }
        }
        return noRepeatStr.toString();
    }
}

Related

  1. createRepeatedString(char c, int length)
  2. repeat(String in, int count)
  3. repeat(String item, int count)
  4. repeat(String pattern, int count)
  5. repeat(String s, int cnt)