• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

fetch from string array into collection

 
Ranch Hand
Posts: 842
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have following program



It is giving output as

[[hello, world],
[Goodbye, planet]]


I want to take out

hello and world
similarly
Goodbye, planet

and put it into some collection etc
so that later i can loop through and query database using
hello as 'username' and world as 'password'

Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
API explains why you get that result here. Check the description of deepToString method.
On the other hand, what you want to do is best accomplished using double for loop, in each iteration of inner one you can get one element, and perform whatever you want with it.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kemal Sokolovic wrote:
On the other hand, what you want to do is best accomplished using double for loop, in each iteration of inner one you can get one element, and perform whatever you want with it.



It is probably more interesting to code it recursively -- as it can be use to flatten out any depth of arrays of arrays.

Henry
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:It is probably more interesting to code it recursively -- as it can be use to flatten out any depth of arrays of arrays. Henry


Agree, but I don't think recursion is something that beginners should play with, and based on the question I think sai rama krishna is one of those.
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why should beginners not play with recursion?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Why should beginners not play with recursion?


Based on what I've seen so far, they find it difficult to catch up with, and even more to implement. Programs usually end up with with stack overflow, end coders being more confused.
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kemal Sokolovic wrote:I don't think recursion is something that beginners should play with


I disagree, some people are very much at home when thinking from recursion point of view... Some find it even more simpler than looping...
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:I disagree, some people are very much at home when thinking from recursion point of view... Some find it even more simpler than looping...


Well, that's your opinion and I must disagree with it. Giving a recursive algorithm to someone who is not comfortable with iterating over two dimensional array doesn't seem to me as a good idea.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:I disagree, some people are very much at home when thinking from recursion point of view... Some find it even more simpler than looping...


I think it depends on your training. Many people with a strong Maths background find recursion quite straightforward; on the other hand, duffers like me find it quite tough. And since good programmers program not only for themselves, but for the person who has to come after them, I'd say there's an argument for not using recursion unless there's a strong reason for doing so (eg, divide and conquer algorithms).

Winston
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with that. There are some problems that are naturally solved with recursion, e.g. quicksort or mergesort algorithm. On the other hand, a task such as printing contents of an array (even a multi dimensional one) implemented recursively would just look more elegant at the expence of efficiency (each time entire frame is pushed onto stack, which consumes both time and memory) and that's not the thing you would want to waste for such trivial tasks.
 
What's that smell? Hey, sniff this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic