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:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Anonymous04:04

    This comment has been removed by a blog administrator.

    ReplyDelete
  6. Anonymous09:07

    This comment has been removed by a blog administrator.

    ReplyDelete
  7. Anonymous07:56

    This comment has been removed by a blog administrator.

    ReplyDelete
  8. Anonymous01:54

    This comment has been removed by a blog administrator.

    ReplyDelete
  9. Anonymous09:38

    This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. Anonymous11:02

    This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete