[我正在尝试通过查看汉字和汉字包含在哪些ArrayList中来对汉字和汉字进行分类。
public static List<String> hskOne = new ArrayList<String>(); public static List<String> hskTwo = new ArrayList<String>(); public static List<String> hskThree = new ArrayList<String>(); public static List<String> hskFour = new ArrayList<String>(); public static List<String> hskFive = new ArrayList<String>(); public static List<String> hskSix = new ArrayList<String>(); public static List<String> hskOneUTF = new ArrayList<String>(); public static List<String> hskTwoUTF = new ArrayList<String>(); public static List<String> hskThreeUTF = new ArrayList<String>(); public static List<String> hskFourUTF = new ArrayList<String>(); public static List<String> hskFiveUTF = new ArrayList<String>(); public static List<String> hskSixUTF = new ArrayList<String>(); public static void main(String[] args) throws InputMismatchException { try { FileInputStream file = new FileInputStream(new File(HSKFILE)); Workbook workbook = new XSSFWorkbook(file); DataFormatter dataFormatter = new DataFormatter(); Iterator<Sheet> sheets = workbook.sheetIterator(); Sheet sheet = workbook.getSheetAt(0); // Extracting HSK 1 words to list for (int i = 0; i < 6; i++) { for (int j = 0; j < 25; j++) { Cell cell = workbook.getSheetAt(0).getRow(i).getCell(j); String cellValue = charToUTF(dataFormatter.formatCellValue(cell)); hskOneUTF.add(cellValue); hskOne.add(dataFormatter.formatCellValue(cell)); } } // Extracting HSK 2 words to list for (int i = 6; i < 12; i++) { for (int j = 0; j < 25; j++) { Cell cell = workbook.getSheetAt(0).getRow(i).getCell(j); String cellValue = charToUTF(dataFormatter.formatCellValue(cell)); hskTwoUTF.add(cellValue); hskTwo.add(dataFormatter.formatCellValue(cell)); } } // Extracting HSK 3 words to list for (int i = 12; i < 24; i++) { for (int j = 0; j < 25; j++) { Cell cell = workbook.getSheetAt(0).getRow(i).getCell(j); String cellValue = charToUTF(dataFormatter.formatCellValue(cell)); hskThreeUTF.add(cellValue); hskThree.add(dataFormatter.formatCellValue(cell)); } } // Extracting HSK 4 words to list for (int i = 0; i < 24; i++) { for (int j = 25; j < 50; j++) { Cell cell = workbook.getSheetAt(0).getRow(i).getCell(j); String cellValue = charToUTF(dataFormatter.formatCellValue(cell)); hskFourUTF.add(cellValue); hskFour.add(dataFormatter.formatCellValue(cell)); } } // Extracting HSK 5 words to list for (int i = 24; i < 50; i++) { for (int j = 0; j < 50; j++) { Cell cell = workbook.getSheetAt(0).getRow(i).getCell(j); String cellValue = charToUTF(dataFormatter.formatCellValue(cell)); hskFiveUTF.add(cellValue); hskFive.add(dataFormatter.formatCellValue(cell)); } } // Extracting HSK 6 words to list for (int i = 0; i < 50; i++) { for (int j = 50; j < 100; j++) { Cell cell = workbook.getSheetAt(0).getRow(i).getCell(j); String cellValue = charToUTF(dataFormatter.formatCellValue(cell)); hskSixUTF.add(cellValue); hskSix.add(dataFormatter.formatCellValue(cell)); } } } catch(Exception e) { e.printStackTrace(); }
charToUTF方法将字符转换为其UTF-8值,而我正在填充两组arrayLists:一组将单词转换为UTF-8,而另一些则不然。这是我正在使用的charToUTF方法:
public static String charToUTF(String str) { String encoded = ""; for(char ch: str.toCharArray()) { encoded += "\\u" + Integer.toHexString(ch | 0x10000).substring(1); } return encoded; }
您可以在https://www.chinesezerotohero.com/hsk-word-vis/处找到我正在使用的excel文件。该文件的每个彩色部分都属于一个不同的arraylist,并且所有列表值都是互斥的。
我的问题是当我运行hskFive.contains("会计")
时,当我检查列表hskFive实际上是否包含此值时,它的评估结果为false。我已经检查了隐藏空间并切换到传统数组,但到目前为止没有任何效果。有人可以告诉我这是为什么以及如何解决?
我正在尝试通过查看汉字和汉字所包含的ArrayList对汉字和汉字进行分类。我已从excel文件中提取了汉字,例如此公共静态列表
您的字符串:
会计