Is there an easy way to convert a Scala object to the string representation specified in the REPL? For example, for Array(2, 3, 5)I would like to receive a line "Array(2, 3, 5)", and for Stream from 2I would like to receive "Stream(2, ?)".
Array(2, 3, 5)
"Array(2, 3, 5)"
Stream from 2
"Stream(2, ?)"
REPL uses a method toStringto generate its string representations of values. Thus:
toString
Array(1, 2, 3).toString // => "Array(1, 2, 3)"
This works in all versions of Scala (2.7, 2.8, etc.).
A more common way is to use the mkString method of the array (the same in 2.7 and 2.8):
scala> val a1 = Array(1, 2, 3) a1: Array[Int] = Array(1, 2, 3) scala> a1.mkString res0: String = 123 scala> a1.mkString(", ") res1: String = 1, 2, 3
Source: https://habr.com/ru/post/1726775/More articles:Why is this happening with Python list.sort? - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1726771/is-this-the-right-way-to-add-items-to-nscombobox-in-cocoa&usg=ALkJrhho0O_JiN-SZKFEhkjW9SBAOYbw3ASwitching system shortcut keys - c #How to clear Java screen output HttpServletResponse - javaWorking with Git in Visual Studio 2010 Beta 2 - GitHow to draw a circle in a Flex MXML file? - graphicsBitmapDrawable with unexpected size in Android 2.0.1 WVGA854 - androidHow can I read pageviews? - javascriptAndroid XML Parsing, omitting "&" - androidРазница между Nhibernate Session.Get и Session.CreateCriteria - nhibernateAll Articles