java - Multidimensional Arrays to store multiple data types -


i know php little. , java little.

i creating small application search text in text area , store result in array.

the array in php this.

array(     "searchedtext" => "the text searched",     "positionsfound" => array(12,25,26,......),     "frequencies" => 23 //this total words found divided total words ); 

but, java not support array multiple data types. in above array, second element "positionfound" of variable length.

later on need iterate through array , create file including above mentioned elements.

please guide me

java support objects. have define class like

class mydata {     string searchedtext;     set<integer> positionsfound;     int frequencies; }  list<mydata> mydatalist = new arraylist<mydata>(); // or mydata[] mydataarray = new mydata[number]; 

and can use structure hold data. there other methods helpful such constructors , tostring() , suggest use ide generate those.

when writing data file, might find json natural format use.


i suggest @ gson nice json library.

from gson documentation, here example

class bagofprimitives {   private int value1 = 1;   private string value2 = "abc";   private transient int value3 = 3;   bagofprimitives() {     // no-args constructor   } } 

(serialization)

bagofprimitives obj = new bagofprimitives(); gson gson = new gson(); string json = gson.tojson(obj);  

==> json {"value1":1,"value2":"abc"}

note can not serialize objects circular references since result in infinite recursion.

(deserialization)

bagofprimitives obj2 = gson.fromjson(json, bagofprimitives.class);   

==> obj2 obj


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -