Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find scala api documentation for string class

Tags:

scala

How to find the API for the String class in Scala. Specifically I need to read the exists method.

like image 316
Balaji Sundaram Avatar asked Oct 26 '25 06:10

Balaji Sundaram


2 Answers

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.

like image 143
Alexey Romanov Avatar answered Oct 29 '25 07:10

Alexey Romanov


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
like image 26
Brian Avatar answered Oct 29 '25 08:10

Brian