My codes are the same with yours. But I count the edges of single cell one by one.

class Solution { public int islandPerimeter(int[][] grid) { int per = 0; for(int i = 0; i < grid.length; i++){ for(int j = 0; j < grid[0].length; j++){ if(grid[i][j] == 1){ if(j-1 >= 0 && grid[i][j-1] == 1)//left per -= 1; if(j+1 < grid[0].length && grid[i][j+1] == 1)//right per -= 1; if(i-1 >= 0 && grid[i-1][j] == 1)//up per -= 1; if(i+1 <grid.length && grid[i+1][j] == 1)//down per -= 1; per += 4; } } } return per; } }Island Perimeter