Logo

Programming-Idioms

History of Idiom 222 > diff from v29 to v30

Edit summary for version 30 by m1ritchie:
New Java implementation by user [m1ritchie]

Version 29

2021-12-16, 10:16:55

Version 30

2022-02-01, 11:52:18

Idiom #222 Find the first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Idiom #222 Find the first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Variables
i,x,items
Variables
i,x,items
Extra Keywords
position
Extra Keywords
position
Code
for(int j=0;j<items.length;j++){
	if(items[j].equals(x)){
		i = j;
		break;
		}
	}
Comments bubble
The .equals() method equates objects.

If equating primitives you would use the “x == y” expression