Android Realm edit

List of primitives RealmListIntegerString...

Realm currently does not support storing a list of primitives. It is on their todo list (GitHub issue #575), but for the meantime, here is a workaround.

Create a new class for your primitive type, this uses Integer, but change it for whatever you want to store.

public class RealmInteger extends RealmObject {
    private int val;

    public RealmInteger() {

    public RealmInteger(int val) {
        this.val = val;

    // Getters and setters

You can now use this in your RealmObject.

public class MainObject extends RealmObject {

    private String name;
    private RealmList<RealmInteger> ints;

    // Getters and setters

If you are using GSON to populate your RealmObject, you will need to add a custom type adapter.

Type token = new TypeToken<RealmList<RealmInteger>>(){}.getType();
Gson gson = new GsonBuilder()
        .setExclusionStrategies(new ExclusionStrategy() {
            public boolean shouldSkipField(FieldAttributes f) {
                return f.getDeclaringClass().equals(RealmObject.class);

            public boolean shouldSkipClass(Class<?> clazz) {
                return false;
        .registerTypeAdapter(token, new TypeAdapter<RealmList<RealmInteger>>() {

            public void write(JsonWriter out, RealmList<RealmInteger> value) throws IOException {
                // Empty

            public RealmList<RealmInteger> read(JsonReader in) throws IOException {
                RealmList<RealmInteger> list = new RealmList<RealmInteger>();
                while (in.hasNext()) {
                    list.add(new RealmInteger(in.nextInt()));
                return list;

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
64 Menu
79 Realm
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close