• Post Reply Bookmark Topic Watch Topic
  • New Topic

Print String  RSS feed

 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain me what this question is trying to ask?

Fill in the implementation for the following Java method so that it recursively prints all Strings in the List and any contained lists.
/**�
Recursively traverses the given list. If an element is a java.lang.String, it is printed to the screen. If it is a java.util.List it is� recursively processed. All other objects are ignored. -**/

*/Public static void printStrings(java.util.List someList) {
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A recursive method is one that calls itself. "Recursively processed" here means that if the list contains a child object that's also a list, then that child list is treated identically to the original list; and the same with any grandchildren, and great-grandchildren, and so on; the method calls itself to process any of these descendants.
 
Rahul Bajaj
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest,
I got the idea of recursive method. Can you explain how to acheive that(how to implement the method)?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question describes the solution almost word for word, although you have to read "traverses" as "uses a 'for' loop."
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!