![]() |
java.Contains(String search) method to be made in Java API ?
Well, I'm not having trouble or anything, but I'm wondering why the String
class doesnt have a contains method? eg public boolean contains(String str) So you could write if(myString.contains("poo" ) { / / Do whatever } Right now the only way to do this (or easiest at least) is to use indexOf(String s) and see if the result isn't '-1'. So I propose: public boolean contains(String full, String searched) { if(full.indexOf(searched) != -1) return true; else { return false; } } Of course, you could make it so it extends the String class, but just an example? I think this form of String manipulation would be most useful in many cases.. Anyone else agree it'd be a useful addition? } |
Re: java.Contains(String search) method to be made in Java API ?
"Alex Zorin" <azorin@tpg.com.au> writes:
> Well, I'm not having trouble or anything, but I'm wondering why the > String class doesnt have a contains method? Because, as you argue yourself, the method would just be a specialization of the general indexOf(). It's not useful to add specialized cases on top of generalized methods; that only leads to library bloat. |
Re: java.Contains(String search) method to be made in Java API ?
"Alex Zorin" <azorin@tpg.com.au> wrote in message news:410cca8e@dnews.tpgi.com.au... > Well, I'm not having trouble or anything, but I'm wondering why the String > class doesnt have a contains method? This is in 1.5 |
Re: java.Contains(String search) method to be made in Java API ?
Intersting idea, but there may be a semantic difference which emans it
doesn't warrent it being made a contains method. Alex Zorin wrote: > Well, I'm not having trouble or anything, but I'm wondering why the String > class doesnt have a contains method? > > eg > > public boolean contains(String str) > > So you could write > > if(myString.contains("poo" ) { > / / Do whatever > } > > Right now the only way to do this (or easiest at least) is to use > indexOf(String s) and see if the result isn't '-1'. So I propose: > > > public boolean contains(String full, String searched) { > > if(full.indexOf(searched) != -1) > return true; > > else { return false; } > > } > > > Of course, you could make it so it extends the String class, but just an > example? I think this form of String manipulation would be most useful in > many cases.. > > Anyone else agree it'd be a useful addition? > > } > > |
Re: java.Contains(String search) method to be made in Java API ?
On 01 Aug 2004 14:27:10 +0200, Tor Iver Wilhelmsen
<tor.iver.wilhelmsen@broadpark.no> wrote: >"Alex Zorin" <azorin@tpg.com.au> writes: > >> Well, I'm not having trouble or anything, but I'm wondering why the >> String class doesnt have a contains method? > >Because, as you argue yourself, the method would just be a >specialization of the general indexOf(). > >It's not useful to add specialized cases on top of generalized >methods; that only leads to library bloat. In jdk5.0, String has the new method: contains(CharSequence cs). So, while it's still just a special case of indexOf(String s), it also works with StringBuffer, StringBuilder, CharBuffer, and any other class that implements CharSequence. Kind of a specialization and a generalization at the same time. |
Re: java.Contains(String search) method to be made in Java API ?
Not that I can find.
sks wrote: > "Alex Zorin" <azorin@tpg.com.au> wrote in message > news:410cca8e@dnews.tpgi.com.au... > >>Well, I'm not having trouble or anything, but I'm wondering why the String >>class doesnt have a contains method? > > > This is in 1.5 > > |
Re: java.Contains(String search) method to be made in Java API ?
"tom bender" <tom@bender.com> wrote in message news:Lf7Pc.370$yt5.22@newsfe2-gui.ntli.net... > Not that I can find. http://java.sun.com/j2se/1.5.0/docs/...#contains(java. lang.CharSequence) |
| All times are GMT. The time now is 02:18 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.