Results 1 to 2 of 2
  1. #1
    Castle is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Printing selected output only

    If I have an output in my console, such as:

    Apples are good
    Bananas are amazing
    Pears are cool
    Fruits are awesome

    How would I go about reading in these output lines and then saying, if the line starts with "Apples" print "good". But reading it all from the line and not hard-coding the "good"?

    So, it wouldn't print every line just "good" because that is the only line that starts with "Apples"? I know there is a startsWith() function, but not sure how to use it when reading in lines.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: Printing selected output only

    How are you outputting the lines? They must be Strings, so you can use any String method on them.

    I'd recommend posting an SSCCE that demonstrates exactly what you're talking about.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to prevent printing the same output 5 times
    By gabrielpr12 in forum New To Java
    Replies: 4
    Last Post: 01-13-2012, 09:47 PM
  2. System.out.println not printing, weird output
    By KonchShell in forum New To Java
    Replies: 9
    Last Post: 03-16-2011, 11:50 AM
  3. Need help with printing console output to JTextArea
    By ShinTec in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2010, 10:10 AM
  4. Having trouble looping & printing output
    By carrotcake in forum New To Java
    Replies: 1
    Last Post: 04-04-2010, 05:37 AM
  5. Replies: 6
    Last Post: 01-30-2010, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •