Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

search methods

 
Tony Cossie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could anyone give me the source code for a linear search method for an array of Strings? and a binary search one too please.
Or where i could get to look at one on a web site maybe.
Thanks for your time
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some handy methods in the java.util.Arrays class ...
 
Tony Cossie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marilyn deQueiroz:
There are some handy methods in the java.util.Arrays class ...

I have to write the code for it, so i will be able to understand how it works. I've found ones for searching arrays of ints but when i change them they don't work for Strings.
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Unpack the source code (src.jar) in your jdk and look at the code in class Arrays. (Hopefully it is implemented in java and not in C or such...).
//Kaspar
 
Tony Cossie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eh how do i do that? Nobody could give me any source code?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The source comes with the jdk. It is in a file named src.jar. Just open that file with WinZip or whatever zip utility that you have and extract the .java file that you want to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic