使用Twitter4j,我收集了一堆推文,然后使用contains()在其中查找单词,但是contains()无法正常工作

时间:2018-08-03 15:15:05

标签: java twitter4j

因此,我使用Twitter4j从Twitter收集了推文,将每个推文添加到名为状态的列表中,然后使用if语句和包含检查每个状态文本中的单词“ the”。如果为true,则将其添加到计数器,然后在最后显示计数器,但是即使tweet中的计数器也始终为0。代码如下:

for (Status status : statuses) {

            String fullTweet = ((follower.getScreenName() + " - " + status.getCreatedAt() + " - " + status.getText()).replaceAll("\\n", "").replaceAll("\\r", ""));

            System.out.println(fullTweet);

            if (fullTweet.toLowerCase().contains("the")) {

                the = the++;

            }

}

1 个答案:

答案 0 :(得分:0)

将您的增量写成the += 1,而不是the = the++,或者简单地写成the++。 您要在增量前分配值,因为变量后有++是后增量。