Search in part of array list - java

can you search, for example, between position 5-10 in the List array?

as?

in this case I need to search between positions 1-5, 5-10, ... and I want to avoid other lists

EDIT: I have something like this

if (pp.move(i).subList(5, 10).contains(pn50.getText())) {

but I have a problem with this code, I need to call a method like:

if (pp.move(i).suit().subList(5, 10).contains(pn50.getText())) {

but I get an error: the subList (int, int) method has an undefined value for the String type, thanks !!

+3
source share
4 answers

You can get a subscription of what you need (which is not an expensive operation), and then search the entire list. For instance:

if (myList.subList(0, 5).contains(objectToFind)) {
   System.out.println("Found object between indexes 0 and 5");
}

UPDATE: first convert the Stits string to a list, if the string is separated by a comma, then you can do it like this:

String[] suitArray = pp.move(i).suit().split(",");
List myList = List list = Arrays.asList(suitArray);

, . , - String, , , .

+5
+2

, ?

ArrayList.subList(fromIndex, toIndex);

, , - "" ( )

0

: subList (int, int) undefined String thanks!!

, suit() String.

0

Source: https://habr.com/ru/post/1790360/


All Articles