1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
package com.gxnu.bigdata.study.datastyle;
import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List;
import org.junit.Test;
public class { public void testArray() throws IOException{ List<String> allLines = Files.readAllLines(Paths.get( "D:", "MyEclipse 2016", "Workspaces", "7-12", "src", "com", "maoge", "study", "io", "IoEx.java"), Charset.forName("UTF-8")); int[] arr = new int[65536]; allLines.forEach((s)->{ for(char ch:s.toCharArray()){ arr[ch-1] = arr[ch-1]+1; } }); for(int i=0;i<arr.length;i++){ char ch = (char)(i+1); if(arr[i]>0){ System.out.println(ch+"出现了"+arr[i]+"次"); } } } }
|
近期评论