Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java.Contains(String search) method to be made in Java API ?

Reply
Thread Tools

java.Contains(String search) method to be made in Java API ?

 
 
Alex Zorin
Guest
Posts: n/a
 
      08-01-2004
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?

}



 
Reply With Quote
 
 
 
 
Michal Dzirba
Guest
Posts: n/a
 
      08-01-2004
[cut]

> Of course, you could make it so it extends the String class, but just an


If by extending you ment subclassing - id be hard as Strings are final.

> example? I think this form of String manipulation would be most useful in
> many cases..


And - i see nothing wrong in using indexOf, or ragexsps for more
complicated requests.
Adding such a feature would sound as an overkill - for me.

Greetings
Michal.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Poll: Is a Java Method an Instance of the Java Classjava.lang.reflect.Method? Please reply with YES or NO. Paka Small Java 15 02-07-2012 07:04 PM
Rebel XT, made in Japan, made in Thailand jazu Digital Photography 10 12-12-2006 05:11 AM
The method add(...) in java.awt.Container made me in confuse Bruce .J Sam Java 2 04-03-2005 12:24 AM
my dream - a simplified version of java - made from java rfractal30 Java 5 02-21-2005 05:54 PM
java.Contains(String search) method to be made in Java API ? Alex Zorin Java 6 08-01-2004 05:03 PM



Advertisments
 



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