Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
    Bookmark Topic Watch Topic
  • New Topic

can you help me with this code?  RSS feed

 
yogesh raipure
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
in this code i get the output written as single string.. but i want it to be written on every new line as
cdaccenter infoway
id 24
fname john
.
.
.
.
but i rather get as cdaccenter infoway id 24 fname john.. so can somebody help me out with this.. here is my code.. your suggestions are welcome..


first page..




second page...
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, Yogesh, and welcome to the Ranch!

First off, you shouldn't post so much code, especially when 90% of it is totally unrelated to your problem.

It's not totally clear what you're trying to do, but it sounds like you have a String consisting of multiple tokens and you want to display each token on its own line. If that's the case, look into String's split() method.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Of course, you will get one line only.. you only write one line and it is built with:

If you do not want to use split() then you need to do something like:

where BREAK is defined using the System properties for the underlying OS line break character(s).

WP
 
yogesh raipure
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
thanks jeff...
I accept that i should not post such long and hectic codes but in my last post when i posted only a part of code somebody got upset.. so i thought that if i post whole code somebody might copy paste it and run it as a whole so as to get what exactly i am getting.. being new i listen everybody saying here.. also i am new to java... so keep on asking even silly things... but i really need your help.. thanks for telling me about split().. but i really find it difficult to get used here... can you explain it even more??
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
yogesh raipure wrote:thanks jeff...
I accept that i should not post such long and hectic codes but in my last post when i posted only a part of code somebody got upset.. so i thought that if i post whole code somebody might copy paste it and run it as a whole so as to get what exactly i am getting..


Yes, you ideally would post code that anybody could copy, paste, compile, run, and get the same results as you. However, that code should only include what's directly relevant to the problem at hand. It should be an SSCCE. This might mean you have to create a whole new program, but you shouldn't hesitate to do so if that's what it takes to get the message across without anything extra.

thanks for telling me about split().. but i really find it difficult to get used here... can you explain it even more??


I can't explain it more if you don't tell me what you don't understand about it. You know that you need to ShowSomeEffort(⇐click) and TellTheDetails,(⇐click) right? So I assume you looked it up in the javadocs, and, if they still left you puzzled, that you googled for java String split examples, and that you then tried it yourself. So, after doing that, what specific problems or questions do you still have?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
William P O'Sullivan wrote:Of course, you will get one line only.. you only write one line and it is built with:

If you do not want to use split() then you need to do something like:

where BREAK is defined using the System properties for the underlying OS line break character(s).

WP


@Yogesh: William raises a good point here. There are two different approaches.

1) You are building the String yourself, and you have total control over how it's built, and you don't ever need it to be a single line. If this is the case, then you can just construct it with the line breaks in the String from the beginning.

2) You're not building the String yourself--it comes from somewhere else; or you are building it, but you have to build it as a single line, etc. If this is the case, then split() would be my first advice, and if you can't or don't want to use that, then you'll have to iterate over the characters of the String yourself, building a new String as you go (with StringBuilder.append()), and inserting line breaks at the appropriate places.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12557
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Since this topic is a duplicate of this, I am closing this thread. Please continue any further discussion in the original thread.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!