|
| |||||||||
| Tags: element, java, javautil, map, programming language, tools, utilities |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Get nth element of a Map
Hello, Here is my map Code: Map <String, Map <String,Integer>> fl2 = new HashMap <String, Map <String,Integer>>(); Code: else if (fl2.containsKey (dp) & &! fl2.get (dp). containsKey (ar))
(
/ / one of them to start
this.tf_answer.setText ( "this flight is not direct");
int msz = fl2.get (dp). size ();
for (int i = 0; i <msz; i + +)
(
System.out.println ( "fl2.get (dp). Get (i). ToS:" + fl2.get (dp). get (i). toString ());
} |
|
#2
| |||
| |||
| Re: Get nth element of a Map
Hello, Elements of a Map did not order, then the "nth element that has no meaning. By cons you can iterate over the contents of the Map. Here is the code you can refer to. Code: for (Integer item: fl2.get(dp).values()) {
/ / Do something with item qq
} |
|
#3
| |||
| |||
| Re: Get nth element of a Map
Hello, Your last technique allows me to juggle it does element by element? I will have then needed to test all the elements he presents are all the same to this this. I will try it in my code , I have any idea for it that is how to use it in the code. Until then, if you have any alternative method for doing the same task then please do post back with that, I am interested to work on it. |
|
#4
| |||
| |||
| Re: Get nth element of a Map
Hello, I am trying the same kind of a code, but this does not work, even the getItem returns null. Here is my code, please verify it. Code: for (int Item: fl2.get(dp).values()) {
System.out.System.out.println("Test"+ fl2.get(dp).get(Item) );
System.out.System.out.println("Key"+ Item ); / / IT WORKS j have a key
System.out.System.out.println("Key values"+ fl2.get(ar).get(Item).function toString() {
[native code]
}() ); / / But in fact the same getItem returns null
} |
|
#5
| |||
| |||
| Re: Get nth element of a Map
Hello, In Your Map, item is a value (see. Values ()), no key. If you want to iterate over the keys, what i am trying to say is this Code: for (String key: fl2.get(dp).keySet()) {
System.out.System.out.println(key);
System.out.System.out.println(fl2.get(dp).get(key));
} |
|
#6
| |||
| |||
| Re: Get nth element of a Map
Hello, I am new to this concept but I have code with me, just have a look at it, it may help you. Here is the code Code: public class MainClass {
public static void main(String[] a) {
Map m = new HashMap();
m.put("key1", "value1");
m.put("key2", "value2");
m.put("key3", "value3");
Set set = m.entrySet();
Iterator ir = set.irator();
while (ir.hasNext()) {
Map.Entry entry = (Map.Entry) ir.next();
System.out.println(entry.getKey() + " -- " + entry.getValue());
}
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Get nth element of a Map" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unable to modify the parent container element before the child element is closed | Flicker | Software Development | 5 | 18-06-2011 08:39 AM |
| Add Or Remove An Element From Jsp | D_chapple | Software Development | 5 | 02-03-2010 12:20 PM |
| How to know whether I am on first element or not in c#? | Constantinee | Software Development | 5 | 22-02-2010 09:58 PM |
| Iterate a sub-element | Vodka | Software Development | 5 | 05-02-2010 12:23 AM |
| What is an XML Element? | Solitario | Software Development | 4 | 29-01-2010 06:38 PM |