java 我可以在领域对象android中拥有字符串的arrayList吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30259676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I have arrayList of string in realm object android
提问by Salmaan
As we dont have any list data type in realm, how can we use ArrayList<String>
in a realm object?
I had same question for the arrayLists of the custom models we make i.e. ArrayList<CustomModel>
but for that I understand that we first have to make RealmObject of same Custom model using
由于我们在领域中没有任何列表数据类型,我们如何ArrayList<String>
在领域对象中使用?
我对我们制作的自定义模型的 arrayLists 有同样的问题,即ArrayList<CustomModel>
但为此我知道我们首先必须使用相同的自定义模型制作 RealmObject
public class CustomObject extends RealmObject {
private String name;
private String age;
}
and then I can use
然后我可以使用
private RealmList<CustomObject> customObjectList;
in another RealmObject
在另一个 RealmObject 中
Do i have to do same with arrayList of string?
1. Making String object
2. Use that object in Realm List
我必须对字符串的arrayList 做同样的事情吗?
1. 制作 String 对象
2. 在 Realm List 中使用该对象
采纳答案by Svetlana Rozhkova
Now it is possible to work with RealmList where T can be the following types: String, Integer, Boolean, Float, Double, Short, Long, Byte, byte[] and Date` (according to the official docs https://realm.io/docs/java/latest/#relationships, see Relationships -> List of Primitives)
现在可以使用 RealmList,其中 T 可以是以下类型:String、Integer、Boolean、Float、Double、Short、Long、Byte、byte[] 和 Date`(根据官方文档https://realm. io/docs/java/latest/#relationships,请参阅关系 -> 原语列表)
For example:
例如:
public RealmList<String> telephoneNumbers = new RealmList<>();
回答by Thomas Goyne
Yes, you have to manually box your strings in a StringObject. We'd like to add support for RealmList<String>
, RealmList<Integer>
, etc., but it's a long way out.
是的,您必须在 StringObject 中手动装箱您的字符串。我们想添加对RealmList<String>
、RealmList<Integer>
等的支持,但还有很长的路要走。