function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hannah CampbellHannah Campbell 

Can someone help me here. Im trying to convert this java code to apex code

Can someone help me here. Im trying to convert this java code to apex code

This is the java code:

String stringVar = "";
if(stringVar.isEmpty()){
   System.out.println("Hello World");
}

This is the code I got so far and im not sure if it is correct:

String stringVar = '';
if(stringVar.isEmpty()){
    system.debug('Hello World');

}
Best Answer chosen by Hannah Campbell
Steven NsubugaSteven Nsubuga
String stringVar = '';
if(String.isEmpty(stringVar)){
    system.debug('Hello World');
}

 

All Answers

Steven NsubugaSteven Nsubuga
String stringVar = '';
if(String.isEmpty(stringVar)){
    system.debug('Hello World');
}

 
This was selected as the best answer
SandhyaSandhya (Salesforce Developers) 
Hi,

Below is the sample code.I would suggest you refer below document to know all the methods with String class in salesforce.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
String empty = '';
String nullString = null;
System.assert(String.isEmpty(empty));
System.assert(String.isEmpty(nullString));
String whitespace = '  ';
String alpha = 'Hello';
System.assert(!String.isEmpty(whitespace));
System.assert(!String.isEmpty(alpha));

Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya