Skip to main content

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Thomson Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Erica Livia Jack Anita Kendall Jamie ThmosonThomson 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Thomson Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie Thmoson 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Thomson Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Erica Livia Jack Anita Kendall Jamie Thomson 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 
added 20 characters in body
Source Link

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Thomson Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie  Thmoson 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Thomson Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie  Thmoson 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 
deleted 10 characters in body
Source Link

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie  Erica  

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie  Erica  

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 

I have a input file like

names.txt

 Maria Derek Erica Livia Jack Anita Kendall Maria Livia Derek Jamie Jack Erica 

I want to output like. Removing duplicates words from the name

output.txt

 Maria Derek Livia Jack Anita Kendall Jamie 

I already tried to read file separated by whitespace and then add them into ArrayList then I lost what to do next to generate output.

import java.util.Scanner; import java.io.*; import java.util.ArrayList; public class duplicate { public static void main(String[] args) throws IOException { ArrayList<String> list = new ArrayList<String>(); File file = new File("weather.txt"); Scanner input = new Scanner(file); String prev = input.next(); int count = 0; while (input.hasNext()) { String next = input.next(); System.out.println(next); set.add(next); count = count + 1; if(prev.equals(next)) { System.out.println("Match found: -" + prev); } prev = next; } System.out.println(list); System.out.println("Word count: " + count); } } 
Source Link
Loading