这里介绍三种合并两个list的方式:
package org.4spaces;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.commons.collections.ListUtils;
import java.util.ArrayList;
import java.util.List;
public class JoinTwoList {
public static void main(String[] args) {
List<String> firstHalf = Lists.newArrayList("四个空格-www.4spaces.org", "微言电影-www.weiyandy.com", "中国健康在线-www.chinahol.com");
List<String> secondHalf = Lists.newArrayList("微言资讯-www.weiyanzixun.com");
new JoinTwoList().joinWithJava(firstHalf, secondHalf);
new JoinTwoList().joinWithGuava(firstHalf, secondHalf);
new JoinTwoList().joinWithApache(firstHalf, secondHalf);
}
/**
* 1.直接使用Java
*/
public void joinWithJava(List<String> firstHalf, List<String> secondHalf) {
List<String> allSites = new ArrayList<>(firstHalf);
allSites.addAll(secondHalf);
System.out.println(allSites.size() + "---" + allSites.get(3));
}
/**
* 2.使用Google guava
*/
public void joinWithGuava(List<String> firstHalf, List<String> secondHalf) {
List<String> allSites = Lists.newArrayList(Iterables.concat(firstHalf, secondHalf));
System.out.println(allSites.size() + "---" + allSites.get(3));
}
/**
* 3.使用Apache Commons
*/
public void joinWithApache(List<String> firstHalf, List<String> secondHalf) {
List<String> allSites = ListUtils.union(firstHalf, secondHalf);
System.out.println(allSites.size() + "---" + allSites.get(3));
}
}
最新评论
网飞没问题, 迪士尼+有解决方案么?
pp助手是安卓手机用的,根本下载用不来苹果
已解决
这样的话数据库里的结构为{"attachment":{"content":"xxx"}}, 要怎么才能变成{"content":"xxx"},从而使结构保持一致?
赞! make test不过的坑都写到的,谢谢楼主~
谢谢你
用了root用户还是一直502是怎么回事呢
student id 是空的