0
我在MongoDB中插入了一个1D short []数组。这很容易,现在我试图检索相同的阵列。它返回一个BasicDBList。我想对列表中的元素进行一些操作。因此,我想将它转换为 Java short []。我怎样才能做到这一点 ?将MongoDB BasicDBList转换为Java short [] Array
以下是代码:
/*将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);
/*获取任何帮助表示赞赏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));
}
}
。谢谢。
Object [] str ='ODarr.toArray(); short [] x = new short [str.length];对于(int i = 0; i
ramasCoder
@ professionallyme86:为什么不把它作为答案? –
@ professionallyme86。精彩。你的答案也有效。 –