ArrayList<String>list = new ArrayList<>(); //1.读取数据 BufferedReader br = new BufferedReader(new FileReader("D:\\java\\xuexi\\Java test\\name.txt")); //2.进行遍历 String ch; while ((ch= br.readLine())!=null){ list.add(ch); }
br.close();
//3.打乱 Collections.shuffle(list); //从零索引开始 String s = list.get(0); //4.进行切割只要名字 String[] split = s.split("-"); System.out.println(split[0]);