猿问

Java数据结构来存储表格数据

我正在用Java解析推文,并想将数据存储到DB,但是我正在寻找一个Java数据结构,该结构可以存储所有检索到的推文,以便以后可以将它们插入DB表中。


我想要的表格是:


|---user---||---tweet---||---date---|


我唯一想到的就是上课Row:


public class Row {


private String user;

private String tweet;

private Date created;


public Row(String user, String tweet, Date created) {

    this.user = user;

    this.tweet = tweet;

    this.created = created;

}


public String getUser() {

    return user;

}


public void setUser(String user) {

    this.user = user;

}


public String getTweet() {

    return tweet;

}


public void setTweet(String tweet) {

    this.tweet = tweet;

}


public Date getCreated() {

    return created;

}


public void setCreated(Date created) {

    this.created = created;

}


}

并实例化一个Row对象,以set()使用该get()方法存储每个tweet,并使用这些方法来检索数据。


非常感谢任何提示,在python中使用几年后再次切换到Java,与心爱的熊猫相比,这些任务似乎并不直观:)


LEATH
浏览 242回答 2
2回答

牧羊人nacy

供将来参考,这是我的解决方案与Row原始问题中定义的类结合使用:&nbsp; &nbsp; public static List<Row> searchTweets() throws TwitterException{&nbsp; &nbsp; Twitter twitter = GetTwitterInstance();&nbsp; &nbsp; Query query = new Query("something");&nbsp; &nbsp; QueryResult result = twitter.search(query);&nbsp; &nbsp; List<Status> statuses = result.getTweets();&nbsp; &nbsp; List<Row> table = new ArrayList<Row>();&nbsp; &nbsp; for(Status tweet: statuses){&nbsp; &nbsp; &nbsp; &nbsp; Row row = new Row();&nbsp; &nbsp; &nbsp; &nbsp; row.setUser(tweet.getUser().getScreenName());&nbsp; &nbsp; &nbsp; &nbsp; row.setTweet(tweet.getText());&nbsp; &nbsp; &nbsp; &nbsp; row.setCreated(tweet.getCreatedAt());&nbsp; &nbsp; &nbsp; &nbsp; table.add(row);&nbsp; &nbsp; }&nbsp; &nbsp; return table;}
随时随地看视频慕课网APP

相关分类

Java
我要回答