In Java, how would I read this text file and insert it into a singely linked lis
ID: 3703682 • Letter: I
Question
In Java, how would I read this text file and insert it into a singely linked list?Emoji_List.txt
1. Grinning Face With One Large and One Small Eye 2. T-Rex 3. Man Zombie 4. Woman Zombie 5. Merman 6. Mermaid 7. Shocked Face With Exploding Head 8. Sandwich 9. Person With Headscarf 10. Flying Saucer 11. Giraffe Face In Java, how would I read this text file and insert it into a singely linked list?
Emoji_List.txt
1. Grinning Face With One Large and One Small Eye 2. T-Rex 3. Man Zombie 4. Woman Zombie 5. Merman 6. Mermaid 7. Shocked Face With Exploding Head 8. Sandwich 9. Person With Headscarf 10. Flying Saucer 11. Giraffe Face
Emoji_List.txt
1. Grinning Face With One Large and One Small Eye 2. T-Rex 3. Man Zombie 4. Woman Zombie 5. Merman 6. Mermaid 7. Shocked Face With Exploding Head 8. Sandwich 9. Person With Headscarf 10. Flying Saucer 11. Giraffe Face 1. Grinning Face With One Large and One Small Eye 2. T-Rex 3. Man Zombie 4. Woman Zombie 5. Merman 6. Mermaid 7. Shocked Face With Exploding Head 8. Sandwich 9. Person With Headscarf 10. Flying Saucer 11. Giraffe Face
Explanation / Answer
The code would be
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class test
{
public static void main(String[] args)
{
LinkedList<String> l=new LinkedList<String>();
try {
Scanner in=new Scanner(new File("C:\My\Java\Chegg\Emoji_List.txt"));
while(in.hasNext())
{
l.add(in.nextLine());
}
in.close();
} catch (FileNotFoundException e) {}
//testing whether it is stored in linked list
ListIterator<String> it=l.listIterator();
while(it.hasNext())
System.out.println(it.next());
}
}
Modify the path according to file path.
The output is
1. Grinning Face With One Large and One Small Eye
2. T-Rex
3. Man Zombie
4. Woman Zombie
5. Merman
6. Mermaid
7. Shocked Face With Exploding Head
8. Sandwich
9. Person With Headscarf
10. Flying Saucer
11. Giraffe Face
Do give a thumbs up
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.