473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Array with text as index?


I am working on a program that accepts data from a web form like this:

Parm Value
Doug Doug
Doug_age 40
Doug_phone 111-222-3333

Kelly Kelly
Kelly_age 42
Kelly_phone 222-333-4444

Basically I get the persons name then an _ and then the parm name. If
I don't get the _ I know that it is the name.

There is more data like address, email, ect.... I would like to store
this data in an array and then eventually insert it into a dataabse.
What I want to do is build an array that holds this data, but has an
"index" by name.

For example:

MyData[Doug][age] = 40;
MyData[Doug][phone] = 111-222-3333;

MyData[Kelly][age] = 42;
MyData[Kelly][phone] = 222-333-4444;
Anyone have an idea how I would go about this?

Thanks,
Doug

Jul 18 '05 #1
2 2567
do*****@kc.rr.com wrote:
I am working on a program that accepts data from a web form like this:

Parm Value
Doug Doug
Doug_age 40
Doug_phone 111-222-3333

Kelly Kelly
Kelly_age 42
Kelly_phone 222-333-4444

Basically I get the persons name then an _ and then the parm name. If
I don't get the _ I know that it is the name.

There is more data like address, email, ect.... I would like to store
this data in an array and then eventually insert it into a dataabse.
What I want to do is build an array that holds this data, but has an
"index" by name.

For example:

MyData[Doug][age] = 40;
MyData[Doug][phone] = 111-222-3333;

MyData[Kelly][age] = 42;
MyData[Kelly][phone] = 222-333-4444;
Anyone have an idea how I would go about this?


Take a look at java.util.Map and its implementations.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #2
do*****@kc.rr.com skrev:
I am working on a program that accepts data from a web form like this:

Parm Value
Doug Doug
Doug_age 40
Doug_phone 111-222-3333

Kelly Kelly
Kelly_age 42
Kelly_phone 222-333-4444

Basically I get the persons name then an _ and then the parm name. If
I don't get the _ I know that it is the name.

There is more data like address, email, ect.... I would like to store
this data in an array and then eventually insert it into a dataabse.
What I want to do is build an array that holds this data, but has an
"index" by name.

For example:

MyData[Doug][age] = 40;
MyData[Doug][phone] = 111-222-3333;

MyData[Kelly][age] = 42;
MyData[Kelly][phone] = 222-333-4444;
Anyone have an idea how I would go about this?

Thanks,
Doug


Write a class for holding a person's data and store the person-objects
in a HashMap with the name as key (- is the first name really always
unique in your app?). (Use a LinkedHashMap if you want order preserved.)
If you really, really want an array, you could of course map names to
indices (in a HashMap). The get-operation is placed in a method like
getIndx(), and this is called where an index is needed:
MyData[getIndx(Doug)][age]. /ulf
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Roy Riddex | last post by:
I've just moved onto 2-D Arrays in my VB6 beginners book. I'm struggling to get my head around the following problem but no doubt you will think it rather easy. My program is supposed to allow up...
13
by: Martin Altschwager | last post by:
Hi, I desperately need some help with what I assume to be a minor problem that I just can't solve. I'm writing a page where on mouseover a link, an image needs to be displayed and some text,...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
1
by: Pradeep Kumar | last post by:
I have a scenario where I am writing a property(using get and set) have to return a member of an object stored in an array of objects! The class user has to pass an index based on which a object i's ...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
7
by: Peter | last post by:
I want to create a multidemensional arraylist. Seeing as they don't exist I was wondering if there is a way to create a class that works like one. I basically want to use it like this Dim...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.