汇才同飞教育汇才同飞学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › for › 日志

请写出一段Java算法,去除数组中重复的字符串  

2019-08-04 18:19:18 查看(209) 回复(0)

 String[] duplicates={"dd","cc","ee","ff","gg","cc","ee"}

package huicai4;


import java.util.Arrays;


public class Chongfu {


public static void main(String[] args) {
// TODO Auto-generated method stub


String[] dup={"dd","cc","ee","ff","gg","cc","ee"};//初始化
 
System.out.println(Arrays.toString(m(dup))); 
}  
 
public static String[] m(String [] b) {
//创建新数组 
String [] a=new String[b.length];
int length=0;
for(int i=0;i<b.length;i++) {
int y=Arrays.binarySearch(a,0,length,b[i]);
         if(y<0) {
          a[length]=b[i];
//           System.out.println(b[i]);
          Arrays.sort(a,0,length);
          length++;
         } 
}
 
 
return Arrays.copyOf(a,length);

}


}


评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.cn 备案号:京ICP备17025800号-2

f1208.com 备案号:京ICP备14030918号-1

返回顶部