How to make a collection to iterate something through?
up vote
0
down vote
favorite
The below code is giving me an error for the keys of "String item:keys". It is saying that an Object cannot be converted to a String. My TA said it's because I don't have the "keys" collection that's being iterated through - it doesn't exist. This is not like the Java import.util.Collection, but the collection of keys being iterated through...I'm not sure how to create it. How and where would I create it?
public String getLongDescription()
{
String str = "You are " + description + ".n"; str+= getExitString() + ".n n"; str+= "This room contains :n";
Set keys = itemsInRoom.keySet();
for(String item : keys)
{
str+=item+":";
str+=itemsInRoom.get(item).getItemDescription() + "n";
}
return str;
}
bluej
add a comment |
up vote
0
down vote
favorite
The below code is giving me an error for the keys of "String item:keys". It is saying that an Object cannot be converted to a String. My TA said it's because I don't have the "keys" collection that's being iterated through - it doesn't exist. This is not like the Java import.util.Collection, but the collection of keys being iterated through...I'm not sure how to create it. How and where would I create it?
public String getLongDescription()
{
String str = "You are " + description + ".n"; str+= getExitString() + ".n n"; str+= "This room contains :n";
Set keys = itemsInRoom.keySet();
for(String item : keys)
{
str+=item+":";
str+=itemsInRoom.get(item).getItemDescription() + "n";
}
return str;
}
bluej
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
The below code is giving me an error for the keys of "String item:keys". It is saying that an Object cannot be converted to a String. My TA said it's because I don't have the "keys" collection that's being iterated through - it doesn't exist. This is not like the Java import.util.Collection, but the collection of keys being iterated through...I'm not sure how to create it. How and where would I create it?
public String getLongDescription()
{
String str = "You are " + description + ".n"; str+= getExitString() + ".n n"; str+= "This room contains :n";
Set keys = itemsInRoom.keySet();
for(String item : keys)
{
str+=item+":";
str+=itemsInRoom.get(item).getItemDescription() + "n";
}
return str;
}
bluej
The below code is giving me an error for the keys of "String item:keys". It is saying that an Object cannot be converted to a String. My TA said it's because I don't have the "keys" collection that's being iterated through - it doesn't exist. This is not like the Java import.util.Collection, but the collection of keys being iterated through...I'm not sure how to create it. How and where would I create it?
public String getLongDescription()
{
String str = "You are " + description + ".n"; str+= getExitString() + ".n n"; str+= "This room contains :n";
Set keys = itemsInRoom.keySet();
for(String item : keys)
{
str+=item+":";
str+=itemsInRoom.get(item).getItemDescription() + "n";
}
return str;
}
bluej
bluej
edited Nov 18 at 9:54
dmcgrandle
808215
808215
asked Nov 18 at 2:07
zonk
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357292%2fhow-to-make-a-collection-to-iterate-something-through%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown