Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HashMap: get arraylist to be a set of key or value

Tags:

java

I have two arraylists A1, A2. Each element of A1 would be the key and each element of A2 the corresponding value. So the solution that I found is looping on A1 ( A1 and A2 have the same size) making hashmap.add(A1[i],A2[i]) but is there a way to directly send the key value pairs as two sets? I want to avoid loops it is going to slow my code..Thank you in advance!

like image 928
user235693 Avatar asked Dec 11 '25 04:12

user235693


1 Answers

"I want to avoid loops it is going to slow my code." Anytime code does anything, it slows down your code. The key is to avoid doing things you don't need to do. Something needs to iterate through your lists.

like image 101
Mark Bolusmjak Avatar answered Dec 12 '25 18:12

Mark Bolusmjak