--- In [email protected], nikhil <nik_...@...> wrote:
>
> Hi rkg,
> 
> I dont know abt an error but I do get a warning from compiler, if I use '+', 
> as shown below, but the
> program still runs( with wrong o/p)
> 
> "warning: there were deprecation warnings; re-run with -deprecation for 
> details
> one warning found"
> 
> Now,
> 'println' requires its args to be of type String, if not, it internally 
> converts them into String,
> by using some form of toString method.
> This works when u provide a single arg like ex: println(nums)
> 
> But when u try to print the concatenated o/p using '+' like for example
> ex: println( nums + nums.tail)  
> you are actually invoking the method called '+' defined for Lists and NOT 
> String.
> 
> The '+' method(for List) adds an element to the end of the list, instead of 
> forming a String
> containing the 2 lists as you intended.
> 
> If you want to use '+', one possible solution is to make sure that the args 
> are Strings themselves
> before they invoke the '+' method.
> 
> ex: println("" + nums + nums.tail)
> 
> Adding a empty String, "", at the beginning makes sure that '+' is invoked 
> for String like
> "".+(nums). The resulting String later invokes '+' again on the next arg.
> 
> Since this method just seems to be some kind of hack, if anyone is aware of a 
> proper
> way to do it, please let me know.
> 
>  
> Regards,
> Nikhil
> 
> 
> 
> 
> ________________________________
> From: rajkumargoel_786 <rajkumargoel_...@...>
> To: [email protected]
> Sent: Friday, 10 July, 2009 1:01:22 PM
> Subject: [twincling] Println
> 
> 
> 
> 
> 
> object lists{
> def main(args:Array[ String]){
> val nums=List(1, 2,3,4,5,6, 7,8,9,0)
> val fruits=List( "Apple"," Banana"," Cheekoo", "Jack Fruit","Grapes" 
> ,"Mango", "Orange", "Papaya")
> println(nums)
> println((nums. tail).tail)
> println(fruits. head)
> println(fruits. tail)
> println(fruits)
> }
> }
> 
> HOW TO WRITE ALL PRINTLN 'S IN ONE LINE
> 
> i AM GETTING ERROR IF I WRITE "+" IN BETWEEN so how do we do that in scala
> Thanks,
> Rajkumar Goel 
> www.twitter. com/rajkumargoel
> 
> 
>    
> 
> 
>       See the Web&#39;s breaking stories, chosen by people like you. Check 
> out Yahoo! Buzz. http://in.buzz..yahoo.com/
> 
> [Non-text portions of this message have been removed]
>
Hi Nikhil,

object lists{
def main(args:Array[String]){
val nums=List(1,2,3,4,5,6,7,8,9,0)
val 
fruits=List("Apple","Banana","Cheekoo","JackFruit","Grapes","Mango","Orange","Papaya")
println((nums::(nums.tail).tail::fruits.head::fruits.tail::fruits).mkString(" 
"))
}
}
~
~
~
This worked without any error,moreover
If I use mkString()method with each and every time and then append the result 
with + operator the resultant output will be completely in String.
Thanks for your reply.
Thanks,
RajkumarGoel
www.twitter.com/rajkumargoel
www.latestfever.blogspot.com


Reply via email to