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
Srinu@dreamsSrinu@dreams 

Integer s2 = new Integer(); is it possible to create like this in apex

String a = 'Java';
String b = new String(a);
String c = 'Java';
System.Debug('***'+a);
System.Debug('***'+b);

Is it possible to create like this in apex,? In java it is possible.

Best Answer chosen by Admin (Salesforce Developers) 
jd123jd123

Hi

 

String a = 'Java';
String b = new String(a);
String c = 'Java';

 

the second line will give an error

 

Type cannot be constructed:

 

you can do like this directly 

 

String b=a;

 

in Apex

-------------

 

In Apex, all primitive data type arguments, such as Integer or String, are passed into methods by value. This means that any changes to the arguments exist only within the scope of the method. When the method returns, the changes to the arguments are lost.

Non-primitive data type arguments, such as sObjects, are also passed into methods by value. This means that when the method returns, the passed-in argument still references the same object as before the method call and can't be changed to point to another object. However, the values of the object's fields can be changed in the method.

 

in jave

-----------

 

String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package.

 

String Methods: As in Java, Strings can be manipulated with a number of standard methods. See String Methods for information.