0

In the following code, Scala is unable to convert Into to String. Why?

object Upper{
    def main(args:Array[String]){
        val number:Int= 1;
        val no=3.3; 
        println(args.map(_.toUpperCase())+(no+number));
    }

}

Error is

error: type mismatch;
 found   : Int
 required: String
                println(args.map(_.toUpperCase())+(no+number));
                                                      ^
one error found
1
  • What exactly are you trying to do here? Are you trying to print the string "[Ljava.lang.String;@...4.3" to the screen? If so, you can just convert no + number to a string yourself using toString or "" +. If not, your problem is not related to the fact that the number isn't converted to a string and you need to explain what you actually want to happen. Commented Sep 19, 2017 at 11:41

1 Answer 1

2

It is because args.map(_.toUpperCase()) returns an Array, not a String. You can use mkString to create a String from the Array:

println(args.map(_.toUpperCase()).mkString(",") + (no + number))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.