How to find the API for the String class in Scala. Specifically I need to read the exists method.
You can't find documentation for the String class itself in Scala API docs because it isn't a Scala class, it's from the Java standard library, so you can find its documentation at https://docs.oracle.com/javase/8/docs/api/java/lang/String.html. Scala-specific methods like exists are added to it using implicit conversions in scala.Predef, which has this to say about String:
The String type in Scala has methods that come either from the underlying Java String (see the documentation corresponding to your Java version, for example http://docs.oracle.com/javase/8/docs/api/java/lang/String.html) or are added implicitly through scala.collection.immutable.StringOps.
There's the online docs and in Scala 2.11.8 the REPL can provide interactive API documentation.
scala> val s = "foo"
s: String = foo
scala> s.exists
override def exists(p: Char => Boolean): Boolean
When I type s. and then hit tab the function definition for exists is shown. So, if we want to see if "f" exists in s we can use the definition shown for exists. i.e.
scala> s.exists(c => c == 'f')
res0: Boolean = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With