List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
if(!(tweet.getUser().getScreenName().toString().equals("gh") || tweet.getUser().getScreenName().toString().equals("gh"))){
List<Status> Stats= tw.getHomeTimeline();
for (Status StatList : Stats) {
if(->here i want to compare HomeTimelin list of tweets with getTweets list<-){
try {
System.out.println(tweet.getUser().getScreenName() );
Thread.sleep(2000);
}
catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
else{
System.out.println("retweeted");
}
}
}
else{
System.out.println("derp blocked");
}
在第二个if语句中我想比较hometimeline列表项和gettweet列表,如果hometime行列表没有来自gettweet的项目我希望它返回转,如果hometime行有它我希望它返回假的。
答案 0 :(得分:0)
您可以使用retainAll来比较两个列表。如下所示:
tweets.retainAll(Stats); // or whatever the names are:
另外作为旁注:变量名应始终从小写字母开始!。
答案 1 :(得分:0)
您可以执行以下操作:
List<Status> tweets = result.getTweets();
List<Status> Stats= tw.getHomeTimeline();
for (Status tweet : tweets) {
if(!(tweet.getUser().getScreenName().toString().equals("gh") || tweet.getUser().getScreenName().toString().equals("gh"))){
boolean found = false;
for (Status StatList : Stats) {
if(StatList.getTweetText().equals(tweet.getTweetText())){
found = true;
break;
try {
System.out.println(tweet.getUser().getScreenName() );
Thread.sleep(2000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}else{
// nothing here
// System.out.println("retweeted");
}
}
if (found) // you can move this and the initialisation(boolean found = false) out side the upper if statement
System.out.println("false");
else
System.out.println("turn");
}else{
System.out.println("derp blocked");
}
}