- String [] str = {"Java", "C++", "Php", "C#", "Python", "C++", "Java"};
- for (String elementA:str ) {
- System.out.print(elementA + " ");
- }
- List<String> list = new ArrayList<String>();
- for (int i=0; i<str.length; i++) {
- if(!list.contains(str[i])) {
- list.add(str[i]);
- }
- }
- System.out.println();
- String[] newStr = list.toArray(new String[1]); //返回一个包含所有对象的指定类型的数组
- for (String elementB:newStr ) {
- System.out.print(elementB + " ");
- }
- System.out.println();
java去掉字符串数组中重复的值
最新推荐文章于 2023-08-09 19:41:39 发布