score:3
Accepted answer
let's go command-by-command:
val it = iterator("(a,((a,b),1.0))")
// here we got iterator on one string
val s1 = it.next // "(a,((a,b),1.0))"
.replace("(" , "") // "a,a,b),1.0))"
.replace(")" , "") // "a,a,b,1.0"
.split(",") // multiple lines in array: "a", "a","b","1.0"
.tostring // array[string].tostring returns what you got: ljava.lang.string;@d70d7a
.split(",") // one string (because there's no "," signs)
maybe you should run tolist
before tostring
, because tostring
is defined in a way you expect it to be defined in this implementation of list
:
val s1 = ...
.split(",")
.tolist
.tostring
...
maybe you should look at java: split() returns [ljava.lang.string;@186d4c1], why? for clarification.
score:2
.split(",")
makes array and .tostring
doesn't work on array and after that you are again spliting by .split(",")
which i don't think helpful.
and you can also use replaceall
in place of multiple replace
scala> val it = iterator("(a,((a,b),1.0))")
it: iterator[string] = non-empty iterator
scala> val s1 = it.next.replaceall("[()]" , "").split(",")
s1: array[string] = array(a, a, b, 1.0)
scala> println("s1 is "+s1(0))
s1 is a
Source: stackoverflow.com
Related Query
- Unable to access String value
- How To Access access Case class field Value from String name of the field
- Scala safe way of converting String to Enumeration value
- Spark dataframe get column value into a string variable
- Extract String value using json4s
- Char or String -> Unicode value in Scala?
- How to access value of map with a key if key was not found in scala?
- How to convert a JSON JString value to an ordinary String in Lift?
- How to access a field's value via reflection (Scala 2.8)
- How to access and update a value in a mutable map of map of maps
- Scala - Convert map key value pair to string
- value isBlank is not a member of String
- Akka-streams - how to access the materialized value of the stream
- jsonpath find string value in the jsonarray independent of array index
- Scala: Access optional value in optional object
- How to make Reflection for getting the field value by its string name and its original type
- Scala AKKA access variable or return a value
- Unable to access file in relative path in Scala for test resource
- Unable to split String using |
- Unable to access current millisecond time in scala using java.lang.System.currentTimeMillis();
- How to check if a map contain a empty string value in scala?
- Value Class w/ String Inner Type?
- Unable to resolve path dependent type class evidence w/o having value type accessible
- How to ignore an item when generating the json string if the value is None?
- Scala int value of String characters
- value || is not a member of String - scala
- Unable to handle String literals size greater than 65535 characters. Compiler throws IllegalArgumentException
- Why is Value String not a stable identifier even when defined as a val
- Scala - calling a method with generic type parameter given a string value that determines the correct type
- Scala flatten a map with list as key and string as value
More Query from same tag
- How to Find Out Per key Maximum in scala collection
- How to call withColumn function dynamically over dataframe in spark scala
- How can I read Json as Map[String,String]?
- How to extract remainder of sequence in pattern matching
- Write concise sbt configurations based on combinations of predefined configuration parameters
- Tail Recursive findNextAndTail in Scala
- How can you make `first` return a `Failure` if both f and g fail?
- Scala constructor with default arg referencing another arg
- Retry a function that returns a Future
- How to get sum of a result from Mysql in scala with play framework?
- Where to put application.conf in Play for Scala standalone?
- Create HMap from HList type
- avoid executing the same method in all scala actions in play framework
- Functional equivalent of if (p(f(a), f(b)) a else b
- Extract part of String using regex and assign it to variable scala
- How to convert array of strings to string column?
- Wait for akka actor system to become available
- How do you fix type mismatch in try-catch blocks?
- Do I need a content provider to stream http video to android.widget.VideoView?
- Integration testing play framework using custom header in a request
- unexpected behavior in eclipse
- How to find degree of each vertex in graph - RDD Transformation?
- How do you define an enum that can only be created by its companion object? (think smart constructors)
- Unloading a Scala Object
- Akka Http get query returning empty response
- Adding an item to scala.collection.mutable.HashMap
- Not able to use assembly plugin
- How to use Status in own code in Play
- Difference between Ad-hoc polymorphism and Parametric polymorphism in Scala
- scala sum By Key function