查找并替换(显示)数组列表中的字符串。我要添加什么(JAVA)

时间:2014-09-19 13:40:01

标签: java arrays string find

我不知道要添加什么。我需要从数组中读取文本并找到我要输入和替换并显示的字符串。谢谢。我只有这个程序才能找到字符串。

import java.util.*;
import java.io.File;

public class RemoveAndReplace {

static ArrayList<String> strings = new ArrayList<String>();

public static void main(String[] args) {
    RemoveAndReplace test = new RemoveAndReplace();
    try {
        Scanner scanner = new Scanner(new File(args[0]));
        while (scanner.hasNext()) {
            strings.add(scanner.next());
        }
    } catch (Exception e) {
    }

    //ArrayList<String> a = new ArrayList<String>(strings);
    while (true) {
        System.out.println("\nPress 1 to remove all occurences of a word \nPress 2 to exit\n:");
        Scanner s = new Scanner(System.in);
        String command = s.next();

          if (command.equals("1")) {
            test.word();
        } else if (command.equals("2")) {
            System.exit(0);
        }
    }
}



public void letter() {

    int let;
    Scanner replaceLetter = new Scanner(System.in);
    System.out.println("What letter/s would you like to remove?");
    String badLetter = replaceLetter.next();
    replaceLetter.close();

    System.out.print(strings);
}

}

0 个答案:

没有答案