将text 文件转为List

Integer 类型
ArrayList<Integer> Mlist = new ArrayList<Integer>(); Scanner scM = new Scanner(new File("D://m.txt"));
     
     
while (scM.hasNextInt()) { int i = scM.nextInt(); Mlist.add(i); }
   
/*将list转为数组*/
       Integer[] Marray = new Integer[Mlist.size()];
       Marray = (Integer[])Mlist.toArray(Marray);

 


String 类型
ArrayList<String> Nlist = new ArrayList<String>(); Scanner scN = new Scanner(new File("D://n.txt")); while (scN.hasNextLine()) { String i = scN.nextLine(); Nlist.add(i); }
/*将list转为数组*/
      String[] Narray = new String[Nlist.size()];
       Narray = (String[])Nlist.toArray(Narray);

 

/*数组转List*/

String[] userid = {"aa","bb","cc"};
List list = new ArrayList(Arrays.asList(userid));

 

posted on 2016-11-19 00:57  w强哥  阅读(533)  评论(0编辑  收藏  举报

导航