0

This is the method through which I would like to store the words in an arraylist and write them to the database.

public void loadWords(Context context) {

    AssetManager am = context.getAssets();
    wordList = new ArrayList<String>();

    try {

        InputStream inputStream = am.open("english-words-lowercase.txt");
        InputStreamReader inputStreamReader = new InputStreamReader(
                inputStream);
        BufferedReader bufferedReader = new BufferedReader(
                inputStreamReader);

        word = bufferedReader.readLine();

        while(word!=null){
            wordList.add(word);
            word = bufferedReader.readLine();

        }

    } catch (IOException e) {
        e.printStackTrace();
    }


}

So now I have an ArrayList with all the words I would like to use. How can I store it into a database so that I can read it whenever I want? And I will be using it to validate words that users will input, is this the best way to store the words or should I use a HashMap or some other storing techniques? Thank you!

1 Answer 1

2

Array list can have duplicates .. so try to store it in a set. and store it in databse..Suppose if you are you have words(a,b,a,c,d).. here 'a' is repeated.. when you are using arraylist it will enter for two times.. but in the case of set it will not allow duplicate..ie 'a' will enter only one time.. and you can store it in database ans retreive when ever you want

Set<String> set = new HashSet<String>();
set.add("element here");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the fast reply, but could you please elaborate on duplicates and set? I am still new to android programming and don't know what a set is or how to make one?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.