java 基礎問題的一些處理,記錄一下,持續更新唄

1. 返回值要返回兩個相互對應的數組,可以用HashMap

    HashMap<String, Point> points = new HashMap<String, Point>();

    使用的時候通過循環來獲取

      for (Entry<String, Point> p : pointsMap.entrySet()) {

            System.out.println(p.getKey()); //   打印HashMap裏面的的鍵,就是String

            System.out.println(p.getValue()); //   打印HashMap裏面的的值,就是Point
      }

2. 判斷文件爲空

import java.io.*;
public class test
{
    public static void main(String args[]) throws Exception{
        FileInputStream fin=new FileInputStream("d:\\empty.txt"); 
        int size=fin.available();
        if(size==0){
           System.out.println("Empty!");
        }else{ 
           System.out.println("Not Empty!");
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章