A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
testing String as immutable
Mike Cunningham
Ranch Hand
Joined: Nov 14, 2000
Posts: 128
posted
Mar 21, 2002 07:35:00
0
Is there a way to
test
that a
String
is immutable by attempting to change the actual string object in the constant pool?
R K Singh
Ranch Hand
Joined: Oct 15, 2001
Posts: 5369
posted
Mar 21, 2002 08:25:00
0
mean ??
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
WiLL Tao
Ranch Hand
Joined: Dec 14, 2001
Posts: 56
posted
Mar 21, 2002 09:13:00
0
Is this code ok?
because "==" is shallow compare,so if string is mutable, the refence address will not be changed.
but this code provdes m1 create new ojbect.
class TestString { public static void main(String[] args) { String m1=new String("test"); String m2; m2=m1; System.out.println(m1); if (m1==m2) { System.out.println("ADDRESS EQUAL"); } m1="test" + "1"; System.out.println(m1); if (m1==m2) { System.out.println("ADDRESS EQUAL"); //false } } }
Thank Folks who <b>Make Sense</b> here.<br />SCJP Platform 2
I agree. Here's the link:
http://aspose.com/file-tools
subject: testing String as immutable
Similar Threads
StringBuffer question
Immutable classes
why string
StringBuffer and String returned from a method doubt
How is this possible if Strings are immutable?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter