无标题文章

环境安装指导:
http://jingyan.baidu.com/article/a501d80c1a7ca4ec630f5eed.html

1.文件读取
链表操作
public static void main(String[] args) {
JavaTest c = new JavaTest();
System.out.println("The ride number is:" + c.getRide("src/testcase/busline1.txt", "A", "C" ));
}
public int getRide(String filePath, String pointA, String pointB) {
if (filePath == null){
System.out.println("Invalid parameter input is null");
return ;
}
BufferedReader br = null;
ArrayList<String[]> allLine = new ArrayList<String[]>();
ArrayList<Point> beginList = new ArrayList<Point>();
ArrayList<Point> endList = new ArrayList<Point>();

    try {
        br = new BufferedReader(new FileReader(filePath));
        
        //TODO: Please add your code here!
        String line = br.readLine();
        while (line != null) {
            //process the line
            String[] tmp = line.trim().split(" ", 0); //字符串,使用空格进行拆分
            allLine.add(tmp);                   
            //read next line
            line = br.readLine();
        }
    } catch (Exception e) {
        System.out.println("open file execption : " + e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                System.out.println("close file execption : " + e);
            }
        }
    }
    
    int beginLineLocal = -1,beginColLocal = -1;
    for(int i=0;i<allLine.size();i++){
        String[] tmpCount = allLine.get(i);    //从链表中取出具体一项
        if((beginColLocal = isHaveStr(tmpCount,pointA))>-1){
            beginLineLocal = i;
            Point myBeingPoint = new Point(beginLineLocal,beginColLocal);
            beginList.add(myBeingPoint);   //添加一项到新的链表中
        }
    }
    return -1;
}

2.排序,比较大小:
添加到链表中,并且排序好:
static class ProcessTimeOrder implements Comparator<MotorCar> {
public int compare(MotorCar b1, MotorCar b2) {
if((b1 != null) && (b2 != null)){
long when1 = b1.inTime;
long when2 = b2.inTime;
if (when1 - when2 > 0) {
return 1;
}
if (when1 - when2 < 0) {
return -1;
}
}
return 0;
}
}

static final ProcessTimeOrder sProcessOrder = new ProcessTimeOrder();

private static boolean addListLocked(ArrayList<MotorCar> list, MotorCar newProcess) {
    int index = Collections.binarySearch(list, newProcess, sProcessOrder);
    if (index < 0) {
        index = 0 - index - 1;
    }
    list.add(index, newProcess);
    return (index == 0);
}


    {  //从小到大排序
ArrayList<Employee> list=null;
Comparator<Employee> comparator = new Comparator<Employee>(){
    public int compare(Employee b1, Employee b2) {
        if((b1 != null) && (b2 != null)){
            int when1 = Integer.parseInt(b1.getIdEmployee());
            int when2 = Integer.parseInt(b2.getIdEmployee());
            if (when1 - when2 > 0) {
                return 1;
            }
            if (when1 - when2 < 0) {
                return -1;
            }
        }
        return 0;
    }
}

Collections.sort(list, comparator);
}

3.字符串常用操作,需要熟练使用
拼接,分割,取其中的某一位
StringBuffer a = new StringBuffer();
a.append("12").append("34");
String[] s1 = propStrings.split("\|");
indexOf() 位置
length() 长度
isEmpty() 空
equals() 相同
charAt() 某一位的字节

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容