-2

I'm beginner in Java environment, accustomed to PHP.

And in Php we can create an array like the code below :

$array['params1'] = 'the first param';
$array['params2'] = 'the second param';

And when i will output $array['params1'] it will be 'the first param'.

But i do not find any similar solutions in Java, do you know something similar ?

Thanks in advance

2

1 Answer 1

4

As @mrblewog said, you might want to readup on data structures and the syntax in Java as it is quite different than php.

To give you an Example:

//      Key     Value
HashMap<String, String> map = new HashMap<>();
map.insert("key1", "value1");
map.get("key1"); // returns "value1"

If you want to store other objects than Strings you will need to change the generic types (written in the <X, Y>).

Sign up to request clarification or add additional context in comments.

1 Comment

Yes i know, but i'm searching in Array instead of Collection.. Thanks a lot for your reply, it is exactly what i need :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.