We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all
How I can make a array of string but like a dictionary in python, e.g. I have a list of names, addres, etc, so I can retrieve this list like I can made in python, for exemple:
mylist[0] = {"Name": "Pedro Paulo", "address": "street number ten", "etc": "etcetera"}
mylist[1] = {"Name": "Nirma Racunda", "address": "street number eleven", "etc": "etcetera01"}
mylist[n] = {"name": "Elektra", "address": "kitchen hell", "etc": "etc02"}
its possible to make anithing like this in processing?
thank's!
Answers
http://processing.org/reference/StringDict.html
Or HashMap.
hi friend, thank you for reply, its dont solve my problem, see above:
1 - Im using beziersqlib to get the data from a table;
2 - I need to retrieve the data of the fields in this table to print it in the screen;
3 - I tried using stringlist to do this, but it returns a large list of all records in the table with a key starting at 0 for the first record in the first field, 1 for the same record in the second field, and so on.
but what I need is to get the first record in all fields of the table to an array, get the second record in all fields in this table in a subarray of that array and so on. I need anything just like a dict in python!
peace!
I don't know nothing about Sql and the way to get your data, but maybe you want a double dimension array?
Perhaps a Table is more organized than a double array:
http://processing.org/reference/Table_findRow_.html
We can use findRow() to search for an entry by providing the column:
http://processing.org/reference/Table_findRow_.html
@GoToLoop as was hoping you would have some to add about initialising the arrays using : {"xxx","yyy"}; ...
Won't you? ;)
Class Table didn't have many tricks to allow multiple inserts. :-S Actually, Java in general isn't good about it at all! ~X(
Most I've come up w/ is having a
String[][]
similar to @_vk. But transferring it to a Table later:I still say that HashMap (in an array if needed) is the structure reproducing what you show.
That's the data structure the closest of what you ask for.
Now, perhaps it might not be the best for your need, as the keys are always the same. A table structure, as given in the other answers, might be better.
shouldn't we go for OOP and make a class "Person" with "Name", "Address", "Etc"
and just an ArrayList of that class?
;-)
Hi @GoToLoop, its work, but I need to make the inverse with you say, e.g. I need to get the data from a table, in your example it is a .csv file, no problem if it is in a sql table fo me, becuase for it I use de beziersqlib to get the data, my doubt is how to pass these data to a array and print it on the screen one by one.
Hi @Chrisir, you can tell-me a example of how I can get a array in a class?
sorry guys, its because Im a python programer and in python, array is so simple, but I need to write a code in java and so I choose processing to make this.
thank's for all
peace!
Unfortunately, Java indeed needs too much boilerplate in order to insert & grab elements from data structures! :-S
There's a Table's undocumented method called getStringRow() which returns a
String[]
of values from a specified row.I did an example of printing a whole row 1 by 1 below. Check it out: (*)
Printing a whole row in 1 line is highly prone to be messy! X_X
As a fix for that I did version 2. This time it prints each column entry in its own line, like a form: *-:)
I am not saying HashTable and Table are not a good solution
the OOP approach is dead simple really.
;-)
Nice, @GoToLoop, its work.
now, you can explain how I can convert it to get these result from a class?
thank you!
I did something like saveTable() + loadTable() + put them into a class in this thread:
http://forum.processing.org/two/discussion/2801/picking-cards-at-random-then-excluding-those-from-further-picking-
But since he only asked for printing arrays, I didn't bother to make a Person class for it! :P
I only know how to insert the result into a class, like @Chrisir's Person! :(|)
thank you all, especially for the @GoToLoop and for @Chrisir, its solved now!