如何比较一个ArrayList中的元素(char)位置比Java中另一个ArrayList中的左元素更大

时间:2022-07-07 21:44:48

Suppose I have two ArrayLists: List one;

假设我有两个ArrayLists:List one;

ArrayList <Character> firstString = [a, b, c, d];

List two;

清单二;

ArrayList <Character> secondString = [f, a, d, b, c, r, g];

As we know, in the first list, a is in position 0, c is in position 2.

众所周知,在第一个列表中,a位于位置0,c位于位置2。

After searching I have found that a and c exist in second array list.

搜索后我发现a和c存在于第二个数组列表中。

How do I compare that position of c is bigger than position of a in secondString ArrayList because of being c bigger in firstString ArrayList?

我如何比较c的位置大于secondString ArrayList中a的位置,因为在firstString ArrayList中c更大?

1 个解决方案

#1


3  

Ok, use this, ArrayList.indexOf(item) will get you the position of the item:

好的,使用这个,ArrayList.indexOf(item)将获得项目的位置:

int positionOfA = secondString.indexOf('a');
int positionOfB = secondString.indexOf('b');

Now compare them!

现在比较一下吧!

#1


3  

Ok, use this, ArrayList.indexOf(item) will get you the position of the item:

好的,使用这个,ArrayList.indexOf(item)将获得项目的位置:

int positionOfA = secondString.indexOf('a');
int positionOfB = secondString.indexOf('b');

Now compare them!

现在比较一下吧!