Advanced Object-Oriented Programming

The most useful property to be able to find out is

Info icon This preview shows pages 8–9. Sign up to view the full content.

View Full Document Right Arrow Icon
The most useful property to be able to find out is the length of an array. This can be accessed using the form: arrayname .length For example, we can easily iterate through an entire array using a for loop by accessing its length property. For example: for (int i = 0; i < A.length ; i++) { … } Strings are full-fledged classes in Java, with many methods for accessing individual characters, finding the length, searching, etc. Probably the most useful method, however, is the equals method, which allows you to compare two strings to determine whether they contain the same sequence of characters (recall that this cannot be done with the == operator, as it just checks whether two things refer to the same object ). For example: String name = T.getText(); // read in a name from // textfield T
Image of page 8

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
if ( name.equals(“Fred”) ) { // not name == “Fred”!!! T.setText(“hello Fred!”); } Copyright © 2000 by Dr. John R. Sullins
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern