Here you can find the source of deleteRepeatStr(String repeatStr, String separator)
Parameter | Description |
---|---|
repeatStr | The String contain the repeat character |
separator | The list separator |
public static String deleteRepeatStr(String repeatStr, String separator)
//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(); } }