去除集合中字符串的重复值
有两种方法,先看第一种。
思路:
- new一个新集合。
- 遍历第一个集合,获取得到每一个元素。
- 用第一个集合取出的元素去新集合里面看,如果有就不管,没有就加入新集合。
- 遍历新集合。
import java.util.ArrayList;
public class Test{
public static void main(String[] args){
List<String> strs=new ArrayList<String>();
strs.add("aaa");
strs.add("bbb");
strs.add("ccc");
strs.add("aaa"