Unsetting variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Unsetting variables

How can I unset any variables in Java such that I can reuse by using different type next time? For example : String a = "String" System.out.print(a); __________//block of code to unset variable 'a' int a = 5 System.out.print(a); I meant just like we use function "unset($variable)" in PHP. Please answer soon !

23rd Oct 2018, 3:22 AM
Googel - avatar
4 Answers
+ 6
you cant, as variable a is assigned to data type String. you can convert a string to int using Interger.parseInt(yourString); but the value of your string would have to be "5" and not "five" also you would have to use a new variable String str = "5"; int a = Integer.parseInt(str); System.out.print(a);
23rd Oct 2018, 4:11 AM
D_Stark - avatar
+ 1
I also don't know
4th Nov 2018, 8:32 AM
Ssebudde Abbey
Ssebudde Abbey - avatar
+ 1
4th Nov 2018, 7:44 PM
Levi Hoerger
Levi Hoerger - avatar
May be easy to do it so? String strA = "string"; Int intA = Integer.parseInt(strA); Or you need String a = null; Start garbage collection, and after try to new a. Idk can be or dont, try...
4th Nov 2019, 8:52 PM
Alexei “vinsler” Kurbatov
Alexei “vinsler” Kurbatov - avatar