Jump to content

Juntar strings em listas diferentes


AJBM

Recommended Posts

Boas,
 

Eu tenho de fazer uma função em Scala que retorne uma lista com a junção de strings  de listas diferentes.
Ex: doStuff(List("ACE"), List("BDF")) Retorna ABCDEF

Eu tenho isto,

def doStuff(l: List[String],l2: List[String]): List[String] = {
val newList:List[String]=List()

if(l.size> l2.size) {
  for((elem,i)<- l.view.zipWithIndex) {
    if(i< l2.size) {
      for((x,j) <- elem.view.zipWithIndex) {
        if(j<l2(i).length()) {
          print( x.toChar +""+ l2(i).charAt(j))
        }
      }
      println()
    }
  }
}
else {
  for((elem,i)<- l2.view.zipWithIndex){
    if(i< l2.size){
      for((x,j) <- elem.view.zipWithIndex) {
        if(j<l2(i).length()){
          print(+l2(i).charAt(j)+ "" +x.toChar)
        }
      }
      println()
    }
  }																					
}		
newList
}

O resultado do print está correto, mas eu precisava de retornar uma lista com esse valor. Não posso usar var.
Alguém tem alguma dica?

Obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.