collction question

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

collction question

Postby bqbqhahabq » Thu Nov 26, 2009 5:49 am

Hi, I have a question about java collection. (maybe not android issue.. sorry)

How can I create String[] arrangement from keys of Map ??

if there are Map like

[a , abc]
[b, hey]
[c, hoho]

I want to get only a, b, c (surely String value) , and put them in to String[] orderly.

It seems simple, but it was hard.

any geek help me.
bqbqhahabq
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Nov 17, 2009 6:57 am

Top

Postby Kur1310 » Thu Nov 26, 2009 10:51 am

U can use th efollowing code snippet......

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.                 Set keys = hm.keySet();
  5.  
  6.                 String[] keysArray = new String[keys.size()];
  7.  
  8.                 int cnt = 0;
  9.  
  10.                 Iterator i = keys.iterator();          
  11.  
  12.                 while (i.hasNext()){
  13.  
  14.                         keysArray[cnt] = i.next().toString();
  15.  
  16.                         cnt++;
  17.  
  18.                 }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


here hm is a hashMap..
but the problem is that list is not in same order in which they are put into the map..
-Kur
Kur1310
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Oct 28, 2009 10:50 am

Postby qlimax » Sun Nov 29, 2009 8:25 pm

Kur1310 wrote:U can use th efollowing code snippet......

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 Set keys = hm.keySet();
  3.                 String[] keysArray = new String[keys.size()];
  4.                 int cnt = 0;
  5.                 Iterator i = keys.iterator();          
  6.                 while (i.hasNext()){
  7.                         keysArray[cnt] = i.next().toString();
  8.                         cnt++;
  9.                 }
  10.  
  11.  
  12.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


here hm is a hashMap..
but the problem is that list is not in same order in which they are put into the map..


if the order matter, use this:
http://java.sun.com/javase/6/docs/api/j ... shMap.html

bye :)
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest