Results 1 to 9 of 9
- 08-27-2008, 06:28 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
How to check whether two elements are available in an array?
For example,
String str1="2"
String str2="3"
String [] str3={"2","4","8","9","3"};
Is there any feature available by default to check whether both str1 and str2 are contained in str3?
Or we can only compare by doing equals() ?
Please give me any suggestions?
- 08-27-2008, 06:37 PM #2
Member
- Join Date
- Aug 2008
- Posts
- 58
- Rep Power
- 0
There are lots of functions in String Class
IndexOf comes to mind at the moment
- 08-27-2008, 06:39 PM #3
If move copy/move/wrap the data from an array into one of the collections classes, you could use some of their methods such as contains().
Otherwise write a loop and use equals against each element.
- 08-27-2008, 06:40 PM #4
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
I will try collection classes, if I find it difficult to handle, I am planning to use only loops as you said..
thanks...
- 08-27-2008, 07:06 PM #5
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
Any other suggestions....?
-
If you sort the array, you could use Arrays.binarySearch(...)
You can find it here.
- 08-27-2008, 09:17 PM #7
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
thanks....
Last edited by venkatteshb; 08-27-2008 at 09:23 PM.
-
note: cross-posted in the sun java forums.
- 08-27-2008, 10:45 PM #9
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Using reflection to check array type and length
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:15 PM -
How an array can check that profile whether exists or not???
By hien_NU in forum New To JavaReplies: 1Last Post: 01-10-2008, 01:18 AM -
reference to elements in array
By Igor in forum New To JavaReplies: 1Last Post: 12-14-2007, 11:56 AM -
problems with asigning elements of an array to a constructor
By rednessc in forum New To JavaReplies: 1Last Post: 12-14-2007, 07:25 AM -
Help with array of elements
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 05:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks