Java: String and Double arrays

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

DYS

Thread Starter
Joined
Dec 28, 2008
Messages
462
Hello people.

I currently have an array of Strings, like so:
Code:
private String catalogue[] = {"Apples", "Bananas", "Oranges", "Bread", "Milk", "Cheese", "Pizza", "Yoghurt", "Carrots", "Cabbage"};
I have to generate a "Shopping List", using a GUI, but I need to assign prices to these array elements also.
I plan to set up and declare the price (such as: double price; ) in a new class. But once I've done this, how do I assign a double value to the Strings as well?

Thanks in advance :)
 

DYS

Thread Starter
Joined
Dec 28, 2008
Messages
462
Okay...

I'll rephrase a little as I've done some research.

Is there anyway I can create a multi-dimensional array that holds two types of objects? Like what I ideally would need to do is create an array to hold Strings and doubles. But I've tried doing this in my JVM, to no avail:
Code:
private String double catalogue[][] ({"blah blah blah"}, {8.5});

That's just an example
Basically, I need to assign a price (a double) to an item for my shopping list (String).

I'd appreciate any help ASAP, as I have to hand in this work by the end of the week.

Thanks people.
 
Joined
Dec 2, 2007
Messages
6
What seems to be the problem, personally I would use a map structure such as
Map<String, Double> shoppingList = new HasMap<String, Double>();
then you can use the collection framework methods which would make things a damn sight easier for you and your code faster and more robust.
Best of luck!
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top