简体   繁体   English

存储一组字符串的最佳方法是什么

[英]What is the best way to store a set of strings

So I have a set of strings: 所以我有一组字符串:

public Set<String> favs = new HashSet<>();

Which I add to in the activity later. 我稍后会在活动中添加。 However I want to be able to read and write these strings from other activities using just one source for all the data I've added a little graphic to try and explain what I mean better. 但是,我希望能够仅使用一个源来读取和写入其他活动中的这些字符串,而我添加了一些图形来尝试解释我的意思。 What would be the best way to store my individual strings in this manner? 以这种方式存储我的单个字符串的最佳方法是什么?

I would want the data to persist on closing the app. 我希望数据在关闭应用程序时保持不变。 At a guess there would be a maximum of about 30 items. 大概最多会有30个项目。 The data would come internally from entered data. 数据将在内部来自输入的数据。

在此处输入图片说明

consider using shared preference. 考虑使用共享首选项。

  public void setValue(Set<String> stringSet) {
        getSharedPreferences(getClass().getSimpleName(), Context.MODE_PRIVATE).edit().putStringSet("key",stringSet).comit();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Java 中存储字符串的公共部分的最佳方法是什么? - What is the best way to store a common part of Strings in Java? 存储字符串列表的最佳方法 - best way to store a list of strings 在HBase中存储和更新Set的最佳方法是什么? - What's the best way to store and update a Set in HBase? 在文件中存储大量对象的最佳方法是什么? - What is the best way to store a huge set of objects in a file? 我无法决定为我想要实现的目标存储字符串的最佳方式 - I cant decide the best way to store strings for what I'm trying to achieve 在 Java Spring 引导项目中存储常用字符串(属性文件/常量类)的最佳方法是什么? - what is the best way to store common strings (properties file / constants class) in Java Spring boot Project? Java匹配字符串的最佳方法是什么? - Java What is the best way to match Strings? 创建代表常量字符串的简单Java Enum的最佳方法是什么 - What is the best way to create a simple Java Enum representing a constant set of strings 在Java中存储SQL查询的最佳方法是什么 - What is the best way to store sql queries in java 使用Hibernate的商店数组的最佳方法是什么? - What is the best way of store arrays with Hibernate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM