2

I have a HashMap object that contains key=>value set which are both integers.

F = java.util.HashMap;
F.put(1, 123);
F.put(3, 432);
F.put(7, 31);

I need to extract keys to the vector. I access keys with:

F.keySet.toArray

It returns Object:

ans =

java.lang.Object[]:
    [1]
    [3]
    [7]

How to convert it to vector ?

[1 3 7]
2
  • what is a regular vector? can you explain please? Commented Nov 17, 2012 at 14:07
  • I mean standard vector like [1 3 7] Commented Nov 17, 2012 at 14:07

2 Answers 2

4

You may try as following:

>> F = java.util.HashMap;
F.put(1, 123);
F.put(3, 432);
F.put(7, 31);
>> vec = cell2mat(F.keySet.toArray.cell)
vec =
     3
     7
     1
>> whos
  Name      Size            Bytes  Class                 Attributes

  F         1x1                    java.util.HashMap               
  ans       0x0                 0  double                          
  vec       3x1                24  double                          
  z         3x1                    java.lang.Object[]   
Sign up to request clarification or add additional context in comments.

Comments

0

is this what you looking for?

Vector V=new Vector();
for(int i=0;i<3;i++)
V.add(ans[i]);

where ans is the Object[] that you have?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.