How to convert String? to String


#1

my function returns String but in return my value is String? what should i do?


#2

String? means that your value can be null. So you have to check that it is not null fist

if(yourResult == null){
  // handle null result, eg. throw exception, return default, etc
}  else {
  return yourResult // kotlin casts this to non null automatically
}

https://kotlinlang.org/docs/reference/null-safety.html


#3
val nullString: String? = "stuff"
nullString?.let{
 println("this is your none null string ->" +it)
}