str="你好|朋友|朋友|你好|朋友你好";如何让中间的“朋友”只显示一次....

解决方案 »

  1.   

    通过SortListDemo的.removeIteranceAndSortIt()进行重复字符串过滤
      

  2.   

    随手写了个很笨的方法、、String str="你好|朋友|朋友|你好|朋友你好"; 
    int count=0;
    StringTokenizer st=new StringTokenizer(str,"|",false);
    String nowstr="";
    while(st.hasMoreTokens()){
    String arr=st.nextToken();
    if(count>0){
    if(arr.indexOf("朋友")!=-1){
    if(!arr.equalsIgnoreCase("朋友")){
    nowstr+=arr.replaceAll("朋友","")+"|"; }
    }else{
    nowstr+=arr+"|";
    }
    }else{
    if(arr.indexOf("朋友")!=-1){
    count=1;
    }
    nowstr+=arr+"|";
    }
    }
    nowstr=nowstr.substring(0,nowstr.length()-1);
    System.out.println(nowstr);
      

  3.   

    我没表达清楚 从表达下:str="你好|朋友|朋友|你好|朋友你好"; 如何让中间的重复的只显示一次....