Pritam Banerjee
Pritam Banerjee

Reputation: 18923

How to convert a var to Int in Scala?

Is there a method to convert a var to Int in Scala?

Suppose I have:

var noOfConcurrentUsers =  sys.env.get("NumberOfConcurrentUsers");

// I need the following
var userNo = noOfConcurrentUsers //some method

I am getting the variable as an environment variable in String format from Jenkins.

Getting error:

 Cannot resolve symbol toInt

Upvotes: 1

Views: 1371

Answers (1)

Pavel
Pavel

Reputation: 1539

Not sure if I understand correct, but if this conversion from Str to Int then:

var noOfConcurrentUsers = "10";

val i : Int = noOfConcurrentUsers.toInt

EDIT

What worked for me was:

var noOfConcurrentUsers =  sys.env.get("NumberOfConcurrentUsers"); 
var noOfUsers = noOfConcurrentUsers.toString().toInt

Let it be a final nail:)

http://www.scala-lang.org/api/2.9.3/scala/util/Try.html

Upvotes: 4

Related Questions