Go to Post Smells like gracious professionalism in here... :) - marshall [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 18-11-2016, 13:11
Nirnaeth Nirnaeth is offline
Coach/Mentor
AKA: Michael Liang
FRC #6367 (The Brooke High ElectroLights)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2001
Location: Boston, MA
Posts: 44
Nirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud of
Re: JAVA 101 help

Quote:
Originally Posted by Ethan_P View Post
You have (door == "t"), this is not recommended.

Strings are objects, unlike ints and other primitive types. And because Strings are objects, you can't use '==' to compare two Strings. You would need to use
string1.equals(string2);
It might be useful to talk about the reason for this.

Let's say I have two Strings:

String a = "blah";
String b = "blah";

When I instantiate these Strings, Java allocates two different memory locations for them. And 'a' points to the first one that has the "blah" data in it, and 'b" points to another location with the "blah" data in it.

That's why a==b returns false, because 'a' and 'b' are pointing to two different objects, even if they have the same value.

The '==' operator in this case checks to see if they are the same object, not if the have 'equal' values.
__________________
Lead Mentor - Team 6367 - The Brooke High ElectroLights
Former Mentor - Team 5969 - The English Skunkworks
Former Mentor - Team 1754 - The Excel Nitro Knights
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 19:55.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi