从RealmResult中提取String列表

时间:2018-02-02 15:17:10

标签: java android realm

我有一个预先填充的领域数据库。 我在那里有以下对象:

public class RLMFormula extends RealmObject {
    @PrimaryKey
    private String idHighTech;
    private String label;

    public String getIdhightech() { return idHighTech; }

    public void setIdhightech(String idHighTech) { this.idHighTech = idHighTech; }

}

我想在ArrayList中提取所有idHighTech,暂时我这样做:

public ArrayList<String> getAllFormulaID() {
    RealmResults<RLMFormula> rlmFormula = realm.where(RLMFormula.class).findAll();

    ArrayList<String> formulaListId = new ArrayList<>();
    for (int i = 0; i < rlmFormula.size(); i++) {
        formulaListId.add(rlmFormula.get(i).getIdhightech());
    }

    return formulaListId;
}

是否有更高效,更快的东西?

0 个答案:

没有答案