Forums Register Login

find value in string

+Pie Number of slices to send: Send
String se[]={"1","2" ,"3","4"};

may i know how to find if String se[] arry has vaule 3 in it?
+Pie Number of slices to send: Send
Well, if you don't want to use foreach, for loop you can convert this array to list and then use ".contains" method to detect the presence of desired string.
+Pie Number of slices to send: Send
String[] se, surely, not String se[].
+Pie Number of slices to send: Send
 

String[] se, surely, not String se[].



Both are valid. String[] se is simple to understand.
+Pie Number of slices to send: Send
actually, there is no need convert to list and then search. another way is:

1. sort the array by using java.util.Arrays//this step is must since you are going for binary search

2.then use binarySearch of java.util.Arrays to find out( the index) the element(3) of the array

3.the binarySearch returns >=0 if and only if the key is found

hth
+Pie Number of slices to send: Send
 

Siddhesh Deodhar wrote:Both are valid. String[] se is simple to understand.



correct
+Pie Number of slices to send: Send
 

Siddhesh Deodhar wrote:Both are valid. String[] se is simple to understand.

String[] se is the recommended format, because the type of se is an array of Strings.
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1647 times.
Similar Threads
stale jdbc Connection
cannot find symbol
TESCO Bangalore
problem in compiling servlet
Stll having problems
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:52:01.