check string contain inside the string array

hi friends,

i have doubt

i have arry like this

String[] groups ={"Manager", "technical",programmer};

i have another string variable test = "manager", i want to check "manager" is contains inside the groups can any one suggest

like in oracle we have exists some this like this in java.

i want to check one string like "manager" exhists inside the group array.

thanks

[415 byte] By [vinukaruna] at [2007-11-27 11:55:04]
# 1

Iterate and use equals...

CeciNEstPasUnProgrammeura at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 2

use

matches(regex)

u r regex wiil be string that u want to match . I u r case it will be "manager"

AmitChalwade123456a at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 3

> matches(regex)

> u r regex wiil be string that u want to match .

Which is not really a general rule. Equals is still simpler.

CeciNEstPasUnProgrammeura at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 4

> Iterate and use equals...

Looks like he will need to use equalsIgnoreCase

kajbja at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 5

Yes u r right .

AmitChalwade123456a at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 6

thanks for the answer, but i dont want to use loop, the same thing is there any way to do it with vector ?

vinukaruna at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 7

Instead of using string array is there any way to do it with vector ?

because i dont want to use loop

vinukaruna at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 8

Store u r elements in vector by put()

AmitChalwade123456a at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 9

> thanks for the answer, but i dont want to use loop,

> the same thing is there any way to do it with vector ?

Why don't you want to use a loop? Odd requirement. Is this homework?

georgemca at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 10

can u please write how to do this, sorry iam beginner to java programminmg

vinukaruna at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 11

Vector V1 = new Vector();

V1.add("Manager");

V1.add("cleark");

V1.add("Manager");

V1.add("cleark");

Use this

AmitChalwade123456a at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 12

> Store u r elements in vector by put()

Do not use Vectors. Old, slow, outdated. And pointless anyway - if theOP does not want to use a loop, he should add the elements to a Hashset, which does *exactly* what he needs without iterating.

CeciNEstPasUnProgrammeura at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 13

but how to check weather a string eg:"manager" exhists using a vector

thanks

vinukaruna at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 14

Use contains(Obj) from vector

AmitChalwade123456a at 2007-7-29 18:59:46 > top of Java-index,Java Essentials,Java Programming...
# 15

> but how to check weather a string eg:"manager"

> exhists using a vector

>

> thanks

Use a HashSet, just as Rene said. It's better in this case. Do also note that the "search" will be case sensitive.

Kaj

kajbja at 2007-7-29 18:59:50 > top of Java-index,Java Essentials,Java Programming...
# 16

Yes hASHsET BETTER THAN Vector

AmitChalwade123456a at 2007-7-29 18:59:50 > top of Java-index,Java Essentials,Java Programming...
# 17

> Use contains(Obj) from vector

No. Never use Vectors if you don't have to, and use set.contains() to do in much less steps than with a list.

CeciNEstPasUnProgrammeura at 2007-7-29 18:59:50 > top of Java-index,Java Essentials,Java Programming...
# 18

> Yes hASHsET BETTER THAN Vector

Everyhing is better than Vector. If you need a synchronized list, use Collections.synchronizedList(). If you don't need it synchronized: leave it altogether and use an arrayList or LinkedList or whetever suits you the most.

CeciNEstPasUnProgrammeura at 2007-7-29 18:59:50 > top of Java-index,Java Essentials,Java Programming...