如何在 java 字符串中查找单词 java 的大小写

how to find in java string case incesitive number of word java

skdoakdoakdoakdpoakdpoakdopkapodkoapdkpoakdpoakdpakpdkapdkpaodkpakdpakdpakdpkpdkadpkapdkpaoooooooooooooooooooooooooooooooooooooooooooooooooooooo dksaodaoddddddddddddddddddddddddddddddddddddddsdkaopdkpadpaokdakdopakdpakpda dksaopdoapkdpakdpoakdpokdkapodpadpakdpoakdopakdopkpoakdpapdkapdpada kdposaodpadpakdopakdpoakdpokpdkpakdopadkpakdkdkpadkakdpakdp

       String test1 = "java java java. JAVA! ";
       String test2 = "h w !!! ...";
       String word ="java";
       int count = 0;

      String strArray[] = test2.split(" ");

      for(int i=0; i < strArray.length; i++){
            if (word.equals("java")) {
                `enter code here`   
                 count++;
            }            
            System.out.println(strArray[i]);
      }

    System.out.println(count);
    test1.toUpperCase() + test1.toLowerCase().concat;
    count++;
    test1.toLowerCase();
    count++;
    System.out.println(count);

如何 return java 中的事件不区分大小写 java 我一直在上网,但运气不好。在 JavaScript 中,我会使用 are,但在这里我是新手,所以请帮忙。所以我需要找到上面建议的 java 不区分大小写的次数

希望这对您有所帮助

String inputString = "java java java. JAVA!";

        int counter = 0;
        Pattern pattern = Pattern.compile("JAVA");
        Matcher match = pattern.matcher(inputString.toUpperCase());
        while (match.find()) {
            counter++;
        }

        System.out.println(counter);
enter code here:
    String regex = "JAVA";
    String input =  "Java java JAVA ss".toUpperCase();
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(input);
    int count = 0;
    List<Integer> index = new ArrayList<>();
    while (m.find()) {
        count++;
        System.out.println("Match number: " + count);
        System.out.println("start: " + m.start());
        System.out.println("end: " + m.end());

        index.add(m.start());
    }
    System.out.println("count: " + count);
    System.out.println("index: " + index.toString());

第一次使用,希望对大家有所帮助

为了良好的秩序:

    Pattern pattern = Pattern.compile("java", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputString);
    int count = (int) matcher.results().count();

或简称:

    int count = Pattern.compile("java", Pattern.CASE_INSENSITIVE)
            .matcher(inputString).results().count();