Created
October 30, 2012 19:57
-
-
Save t0dd/3982607 to your computer and use it in GitHub Desktop.
Java custom ArrayList toString()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A custom toString method that returns a meaningful string representation of an ArrayList object | |
public String toString() { | |
String strOutput = "MyArrayListObject ["; //Prints constructor name + left bracket | |
for(int i = 0; i < myArr.size(); i++){ //myArr = ArrayList instance variable | |
strOutput += myArr.get(i) + ", "; | |
} | |
strOutput = strOutput + "]"; | |
return strOutput; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment