Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class task3i
- {
- static ArrayList wordArray = new ArrayList();
- static ArrayList<String>noDupes = new ArrayList();
- static ArrayList<String>Dupes = new ArrayList();
- public static void main(String [] args)
- {
- try
- {
- FileReader FR1 = new FileReader("ImportantSentence.txt");
- BufferedReader BR1 = new BufferedReader(FR1);
- String speech;
- while((speech = BR1.readLine())!= null)
- {
- String [] yeha = speech.split(" ");
- Dupes.addAll(Arrays.asList(yeha));
- }
- for(int i=0; i<Dupes.size(); i++)
- {
- if(noDupes.contains(Dupes.get(i))==false)
- {
- int PosOfWord = i;
- wordArray.add(PosOfWord + 1);
- noDupes.add(Dupes.get(i));
- }
- else
- {
- int PosOfWord = Dupes.indexOf(Dupes.get(i));
- wordArray.add(PosOfWord + 1);
- }
- }
- }
- catch(Exception ex)
- {
- System.out.println("Error Occurred");
- }
- for(int i=0; i<noDupes.size();i++)
- {
- int position = Integer.parseInt(wordArray.get(i).toString());
- Dupes.add(noDupes.get(position-1));
- }
- try
- {
- int counter =0; //counter to control list
- BufferedWriter BW1 = new BufferedWriter(new FileWriter("wordfile1.txt"));
- BufferedWriter BW2 = new BufferedWriter(new FileWriter("wordfile2.txt"));
- do
- {
- BW1.write(Dupes.get(counter).toString() + " ");
- counter++;
- }while(counter < Dupes.size());
- BW1.close();
- counter =0;
- do
- {
- BW2.write(noDupes.get(counter).toString() + " ");
- counter++;
- }while(counter < noDupes.size());
- BW2.close();
- }
- catch(Exception ex)
- {
- System.out.println("Error occured when writing file.");
- }
- }
- }
Add Comment
Please, Sign In to add comment