JAVA, EntrySet(), iterator

  • #1
117
3
Using the following code:

Code:
Set<Map.Entry<String,JsonElement>> mySet = jsonObject.entrySet();
for(Map.Entry<String,JsonElement> singleItem : mySet)
{
	singleItem.getKey();
	System.out.println("Set values: " + mySet);
}

mySet gets printed to the console as:

Code:
Set values: [columnGridContainer="[[1,\"1\",\"Default Value\",\"Y\",\"N\",\"0\",\"Left\",\"Default Value\",\"Default Value\",\"Default Value\",\"Default Value\",\"Left\",\"Center\",\"Center\",\"Center\",\"#000056\",\"None\",\"Date/Time\",\"No Filter\",\"N\"]]", header_row_2_enabled="Y", header_row_3_enabled="Y", header_row_4_enabled="Y", col_widths_units="pixels", default_sub_rows_closed="Y", extjs_component="grid", refreshrate="181", title="everything works right", subtitle="except display for checkboxes....", autoheight="N", bottom_buttons="N", col_label_source="col_config_table"]

I need to iterate through the values and put them into an array. Please provide some direction as to how to iterate over this mapped entrySet and enter each value into an array.
 

Answers and Replies

  • #2
194
3
You are printing out the whole set in your for loop, don't you want to look at each item? Like this:

Code:
Set<Map.Entry<String,JsonElement>> mySet = jsonObject.entrySet();
System.out.println("mySet as 'key : value'");
for(Map.Entry<String,JsonElement> singleItem : mySet)
{
	System.out.println(singleItem.getKey() + " : " + singleItem.getValue());
}
 

Related Threads on JAVA, EntrySet(), iterator

Replies
17
Views
4K
Replies
16
Views
499
Replies
2
Views
10K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
8
Views
978
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
10K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
1K
Top