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 2 of 2

Thread: Required Code snippet for the following question

  1. #1
    Junior Member
    Join Date
    May 2014
    Location
    Hyderabad
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Required Code snippet for the following question

    Hi,

    I have a list of strings For Eg: s1 = "20 - 30" , s2 = "10 - 30", s3 = "30 - 30".

    Now, I have a text file which has some 100 lines. So , I have to read each line of the fiel and check if the line contains any of the above strings. If yes, I will do implement my logic.

    Can you please provide me any other solution than the below which I thought.

    My Logic:

    List<String> list = new ArrayList<String>();
    list.add(s1);list.add(s2);list.add(s3);

    Iterator i = list.iterator();

    Reading the each line logic
    {
    for each line
    {

    While(i.hasnext())
    {
    if(line.contains(i.next()))
    {

    // implement your logic
    }
    }
    }

    let me know any thing shortest way than this.

    Thanks,
    Adithya


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Required Code snippet for the following question

    Unformatted code - even pseudocode - is much harder to read than formatted code properly posted in code or highlight tags. Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    What does the "// implement your logic" block do with the target Strings once they are found? What is done there is important to the design of the rest of the program.

Similar Threads

  1. Code Required in the form of Key Values
    By AdithyaChivukula in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 20th, 2014, 07:55 AM
  2. simple code help required
    By rzzz in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 16th, 2014, 07:53 AM
  3. Replies: 0
    Last Post: November 16th, 2012, 05:25 AM
  4. Replies: 5
    Last Post: September 17th, 2011, 09:05 PM
  5. Code snippet pls?
    By srinivas0615 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 30th, 2011, 02:28 AM