-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImmutableVsMutable.java
More file actions
40 lines (35 loc) · 1.03 KB
/
ImmutableVsMutable.java
File metadata and controls
40 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.awt.Point;
public class ImmutableVsMutable
{
public static void main(String args[])
{
Point myPoint = new Point( 0, 0 );
System.out.println( myPoint );
myPoint.setLocation( 1.0, 0.0 );
System.out.println( myPoint );
String myString = new String( "old String" );
System.out.println( myString );
myString.replaceAll( "old", "new" );
System.out.println( myString );
/**
* When we see the output of above program we see this
* java.awt.Point[x=0,y=0]
* java.awt.Point[x=1,y=0]
* old String
* old String
*
*/
System.out.println("**********************************************");
System.out.println("**********************************************");
System.out.println("**********************************************");
System.out.println("**********************************************");
String myStringNew = new String( "old String" );
System.out.println( myStringNew );
myStringNew = new String( "new String" );
System.out.println( myStringNew );
/**
*
*
*/
}
}