Question

I have a question regarding java programming. If I have this in a text file, "...

I have a question regarding java programming.

If I have this in a text file, " hey you <hello world> "

How can I get it so that it only extracts the words in between the "< > " ?

I am doing this with a stream and I know you can get it with the .map() function but I cannot figure out how to do it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find below java code to do so:

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) throws IOException {
        String filename = "/home/beenoo/HomeworkLib/text.txt";

        Stream<String> stringStream = Files.lines(Paths.get(filename))
                .map(input -> input.substring(input.indexOf("<") + 1, input.lastIndexOf(">")));
        stringStream.forEach(System.out::println);
    }
}
Add a comment
Know the answer?
Add Answer to:
I have a question regarding java programming. If I have this in a text file, "...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT