How do I find a character followed by a character in a char array Java?

David :

I am trying to find a character array inside of a character array so that in the array, A would be followed by B. For some reason, I do not get an error but I also cannot get it to do the work I want when I have an array with the combination. I was just wondering if someone could explain what I am doing wrong and point me in the right direction.

char[] Array = new char[] {'A','B','C','D'....};
char A = 'A';
char B = 'B';
....
for (int i = 0 ; i < Array.length; i ++) {
  if (Array[i] == A && Array[i++] == B) {
    //Work Here
  }
}
vahdet :

First, ont to make i + 1 exceed array indexes, use i < arr.length - 1 in for loop. Then, change arr[i++] to arr[i+1] in if statement.

char[] arr = new char[] {'A','B','C','D'....};
char a = 'A';
char b = 'B';
....
for (int i = 0 ; i < arr.length - 1; i++) {
    if (arr[i] == a && arr[i+1] == b) {
        //Work Here
    }
}

P.S: prop names are switched from capital case on purpose, to be consistent with the Java naming conventions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i find the numbers that is not followed by a word character with regex?

Use recursion to find a specific character followed by another specific character in a char[]

java - How do I display a character array in a JTextField

How to find index of character in char array in C#

How do i convert a character array to a string?

How do I return a character array from char *functionName(int arrayname[SIZE]);

How do I make my method count the character of 'a' in the main char array?

How do I type a special character on top of a character in java(FX)

How do I read input character-by-character in Java?

How to convert varchar to varbinary where each char is followed by a null character?

Find 'word' not followed by a certain character

Find a match but not if followed by a specific character

How do I replace the " character in Java?

How do I make a string with a " character in it? (Java)

How can I clear a single character from a char array?

How do I convert a single character String to a char?

Regex to remove a character if followed by another character in java

Using JQuery, how do I check that a string is a letter character followed by eight digits?

grep command to find out how many times any character is followed by '.'

How do I convert a single character code to a `char` given a character set?

What is the ^I character and how do I find it with sed?

Append a single character to a string or char array in java?

in java, change size of char array with null character

How to check if a character matches another character in a char array?

How do I find out if first character of a string is a number?

How do I find the source or a rogue character on my page?

How do I find which character "var in var" is in in python

How do I find a character and look forward and back?

How do I find a character matching my alt code