Convert MongoDB BasicDBList to Java short[] Array -


i have inserted 1d short[] array mongodb. easy.now trying retreive same array. returns basicdblist.i want manipulation on elements of list. hence, want convert java short[] back. how can ?

following code:

/* insert 1darray*/

    db db = (new mongoclient("localhost",27017)).getdb("test1darray");     dbcollection dbcollection = db.getcollection("test1darray");     basicdbobject aisdocument = new basicdbobject();     aisdocument.append("tdarray",out1d);     dbcollection.insert(aisdocument); 

/* fetch 1darray*/

    objectid mlmatrixobjectsid = (objectid)aisdocument.get( "_id" );     system.out.println(mlmatrixobjectsid);     basicdbobject fields = new basicdbobject();     fields.put("_id", mlmatrixobjectsid);     dbcollection dbcollectionfetch = db.getcollection("test1darray");     dbcursor cursor = dbcollectionfetch.find(fields);      basicdblist odarr=null;     while (cursor.hasnext()) {         odarr = (basicdblist)(cursor.next().get("tdarray"));         for(int cell=0; cell < odarr.size(); cell++){             system.out.println(odarr.get(cell));         }     } 

any appreciated. thank you.

object[]  str  =  `odarr.toarray(); short[] x  =  new short[str.length]; (int = 0; < str.length; i++) {   x[i]=((integer) str[i]).shortvalue();} 

does ?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -