0

Is it possible to get the index of a set of values in a document using Java just as you can do with indexOf() in array? I have tried to look it up in the Notes help but could not find and helpful tip.

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
simon peter
  • 403
  • 8
  • 19

3 Answers3

1

First you have to create a Vector of your item's values with getValues() and then you can use indexOf():

Item item = doc.getFirstItem(itemName);
int index = item.getValues().indexOf("yourValue")

As an alternative, you can use Document's getItemValue() to get the Vector of your item's values:

int index = doc.getItemValue(itemName).indexOf("yourValue")
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
0

No, you have to take the text from the document and to parse it. Take a look here.

Community
  • 1
  • 1
florinm
  • 11
  • 2
0

After this line of code...

Vector v = session.evaluate("@Member(\"value\";\"itemName\")");

v.firstElement() will contain the index of the value you are searching for, but it is one-based instead of zero-based. I.e., if the first value in the item matches the value you are looking for, the return is 1, not the 0 that would expect for indexOf() with a Java ArrayList.

Note: the fact that evaluate() returns a Vector seems odd in this context, but most Notes formula language constructs can return either a single value or a list, depending on values in the document, so it always returns a vector even when the formula really only returns one value.

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41