java 小技巧

xiaoxiao2021-02-28  80

一、函数返回值 1、return操作,如果返回值为多个,寻找或者构造一个数据结构带回去 2、使用如下方法,用入参带回来

TestKNN t = new TestKNN(); String datafile = new File("").getAbsolutePath() File.separator "resource" File.separator "datafile.data"; try { List<List<Double>> datas = new ArrayList<List<Double>>(); t.read(datas, datafile); ... } public void read(List<List<Double>> datas, String path){ try { BufferedReader br = new BufferedReader(new FileReader(new File(path))); String data = br.readLine(); List<Double> l = null; while (data != null) { String t[] = data.split(" "); l = new ArrayList<Double>(); for (int i = 0; i < t.length; i ) { l.add(Double.parseDouble(t[i])); } datas.add(l); data = br.readLine(); } } catch (Exception e) { e.printStackTrace(); } }
转载请注明原文地址: https://www.6miu.com/read-79152.html

最新回复(0)