How to store an arraylist in an android database and retrieve it whenever I need to -
this method through store words in arraylist , write them database.
public void loadwords(context context) { assetmanager = 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 have arraylist words use. how can store database can read whenever want? , using validate words users input, best way store words or should use hashmap or other storing techniques? thank you!
array list can have duplicates .. try store in set. , store in databse..suppose if you have words(a,b,a,c,d).. here 'a' repeated.. when using arraylist enter 2 times.. in case of set not allow duplicate..ie 'a' enter 1 time.. , can store in database ans retreive when ever want
set<string> set = new hashset<string>(); set.add("element here");
Comments
Post a Comment