Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to format text in java?

  1. #1
    Junior Member fourseven's Avatar
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to format text in java?

    How do i format text in java. for example i have firstname and lastname. how can i format the text to make it look like lastname is on its column.

    instead of looking like:
    John Brown
    Peter Pan
    Jo Jackson
    Daniel Liberti
    Last edited by fourseven; May 20th, 2009 at 11:51 PM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Formating text

    I am a bit confused fourseven,

    If this is your input:

    John Brown
    Peter Pan
    Jo Jackson
    Daniel Liberti

    What does the output look like?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member fourseven's Avatar
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Formating text

    oh sorry, forgot to put that in.
    here is how i want it to look like


  4. #4
    Little Star
    Join Date
    May 2009
    Posts
    30
    Thanks
    0
    Thanked 9 Times in 7 Posts

    Default Re: Formating text

    You can use tabulator instead of space to align them.

    // \t = tab
    String name = "John\tBrown" ;

    Sometimes you have names that are longer than tab, so you will need to find the length of the longest name and then use it to find out how many tabs you will need to align all of them perfectly.

    If you are not presenting this in commando line then another way to do this would be to use labels. One label where first names will stand and another label for last names
    Last edited by Dalisra; May 16th, 2009 at 09:59 PM.

Similar Threads

  1. Text Processing with Regular Expressions explained in Java
    By JavaPF in forum Java Programming Tutorials
    Replies: 3
    Last Post: February 8th, 2022, 05:16 PM
  2. Java program to reduce spaces between the words in a text file
    By tyolu in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: May 13th, 2009, 07:17 AM
  3. [SOLVED] Enhancement in program of removing whitespace from text file
    By John in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: April 27th, 2009, 09:36 AM
  4. Problem in implementing mortgage calculator
    By American Raptor in forum AWT / Java Swing
    Replies: 1
    Last Post: April 1st, 2009, 02:09 PM