Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (37)

Sign In or Sign Up now to post a comment!
  • why can't you use equals() instead of contentEquals()? What's the difference... for the most part?

  • Excelent Tutorial, ALL..

  • this is a string, for the most part.....HAHAHAHA... love it.

  • Dude, we know Java already.

  • "Hey, if you need anyone to set up some buttons in Java .. I'm you're man!"

    that's gonna be my new pickup line for sure.

  • 'For the most part"

    Everybody drink!

  • I tested it with variable.containts(" "); and it works as well as contentEquals(" ")

  • I'm going to kill myself if I hear "for the most part" again :(

  • @zazzlescat let me help you... "for the most part"

  • Is there any way to include an OR statement in? Eg. IF (condition1 OR condition2)?

    Like how it works with adding an & to make a (condition1 & condition2) statement.

  • @tehjow * if(x || y){} *

    || is the logical OR operator, similarly && is AND and ! is NOT.

  • Yeah Cheer up for the most part.. :)))) jk, travis you're awesome! Thanks

  • I think reason why you cannot use == for conditions for your if to check your String is, String is an Array of chars, which means String can be char[] as well. so by doing if(check == "left"), you are trying to compare "left" with char[0], and char[0] is character 'l'. It's only what I thought btw. Additionally, if you call an array, without specifying it's location in the array, just like only using check, it will call the first element of that array.

  • @Mrgreatestfreakout Nope, vilham437 is right. The reason is that a string is an "object" and you can't compare objects with the == sign because with that you will compare the location of the objects, so when you compare two strings a & b with text "hello world" on both of them, you will get false because those are two objects at different locations, even when they have the same text in them.

  • what a great people gathered up here, cheer up guys!

  • DUUUUUDDEEE, LEARNING SOOO MUCH. Thank you! Have background in Java, but it's been awhile, and I want to get into Android programming. Been following your tut's, going to 200 baby! :D

  • Comment removed

  • errors are a good thing it will train you to fix somthing and fin the broken part

  • I really like these tutorials...for the most part.

  • where is tutorial 27, anyone know? thanks

  • @jakewestgomila /playlist?list=PL33384E9848C4F­55E

  • where's Tutorial 27?

  • can't we use == instead of .contentEquals() ?

  • @xXxDiukexXx he explained that u cant in the tutorial..

    this is java what do u expect =/

  • Comment removed

  • @mastermax7777 There is a giant difference between = and ==. You're probably new, but = is the assignment operator to assign a variable something. And == is the comparing operator, to compare two things. .contentEquals should be the same as ==. So I've got the same question. And yes, also java uses ==.

  • @joannis11 new to java? maybe yes but im not an idiot :)

    if he said you should use contentEquals then he said it for a reason.

  • @joannis11 Wrong. That will simply compare if they are initialized in the same way. Since String is a class and not a variable type, per se, you have to use a method to compare them.

  • @xXxDiukexXx you cannot use == to compare the contents of strings or any other objects because == with objects is checking to see if they have the same location in memory instead of checking to see if the strings contain the same word. The .contentEquals() method compares the actual strings instead of the memory location

  • @vilham437 Same memory location? Are you sure? I thought it checked if the reference was to the same _OBJECT_, I might be wrong though

  • @noideayo he is right

    if you compare primitives like int, long or float then == compares values

    But if you do == on object variables (aka reference types) then it compares memory addresses.

    It pretty much comes down to the inherently different nature of primitive types vs reference types(objects like String)

    When you declare primitive variable it stores the value b/c they have fixed byte length. But objects have different sizes and you can't easily reserve memory so u store address instead

  • @Mr1159pm I'be been coding for years and your comment made me understand primitives vs objects from a new perspective.

  • @vilham437 This is true only for java. In c# or Python you can use == to compare Strings

  • @vilham437 Or .equals()

  • @vilham437

    but if strings got the same contain, they just take the same place in memory

    example, if u got 20 strings and "lol" in them, it just will create one String object

    so you can check contain of the strings

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more