• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with this code?  RSS feed

 
Arun S. Nair
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

/**
*
*/
public ArrayList<String> getBuiltInDevices()
{
for(String string: builtInDevices)
{
return string.replace("[","").replace("]","");
}
return builtInDevices;
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did the compiler say when you tried to compile it?
 
Arun S. Nair
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message was:
incompatible types-found java.lang.string but expected java.util.ArrayList<java.lang.String>
It highlighted the return string.replace part.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you have declared the getBuiltInDevices method to return an ArrayList of Strings but you try only one String rather than an ArrayList.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!