Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   java.Contains(String search) method to be made in Java API ? (http://www.velocityreviews.com/forums/t135753-java-contains-string-search-method-to-be-made-in-java-api.html)

Alex Zorin 08-01-2004 10:48 AM

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?

}



Tor Iver Wilhelmsen 08-01-2004 12:27 PM

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.

sks 08-01-2004 12:27 PM

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



tom bender 08-01-2004 12:37 PM

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?
>
> }
>
>


Alan Moore 08-01-2004 02:30 PM

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.

tom bender 08-01-2004 02:38 PM

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
>
>


sks 08-01-2004 05:03 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57