From Java To Objective-C: String

From Java To Objective C: Strings

My Notes (part 2)


This is a very short introduction from my notes.

A good and complete starting point can be found by google.


The String.


In java we have String Class that represent a string, in objective C there is a NSString object.

Each string constant double quote in objective-c must be prefixed by @

Also in objective C, NSString is immutable like java String.



.objective c version


  • NSString aString = @"hello world";

  • NSString aString2 = [[NSString alloc] initWithString:@"Hello World2"]; 
  • [aString release]; 

  • #define CONSTANT1 @"HELLO";

  • NSLog(@"debug string");

  • NSString *ageString = [NSString stringWithFormat:@"%@ concatenate with %@", "age:", 18];


.java version


  • String aString = "hello world";

  • String aString2 = new String("Hello World 2");

  • public static final String CONSTANT1 = "HELLO";

  • System.out.println("debug string");

  • String ageString = "age:" + " concatenate with " + 18;



12 comments:

與榮 said...
This comment has been removed by a blog administrator.
Webmaster said...
This comment has been removed by a blog administrator.
珍雅 said...
This comment has been removed by a blog administrator.
Giuseppe Morreale said...
This comment has been removed by the author.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
07_TeddyF_Silvey0 said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
張盈 said...
This comment has been removed by a blog administrator.