YouTip LogoYouTip

Java Arraylist Tostring

# Java ArrayList toString() Method [![Image 3: Java ArrayList](#) Java ArrayList](#) The toString() method converts an ArrayList object to a string. The syntax for the toString() method is: arraylist.toString() **Note:** arraylist is an object of the ArrayList class. **Parameter Description:** * None ### Return Value Returns the string representation of the arraylist. ### Example Convert an ArrayList to a String type: ## Example import java.util.ArrayList; import java.util.Comparator; class Main { public static void main(String[] args){ // Create a dynamic array ArrayList sites =new ArrayList(); sites.add(""); sites.add("Google"); sites.add("Wiki"); sites.add("Taobao"); System.out.println("Website List: "+ sites); // Convert ArrayList to String type String list = sites.toString(); System.out.println("String: "+ list); } } The output of the above program is: Website List: [, Google, Wiki, Taobao]String: [, Google, Wiki, Taobao] In the example above, we created an array named sites. Note this line: String list = sites.toString(); We use the toString() method to convert the arraylist to a string, which converts the entire arraylist into a String type. Note: The ArrayList class does not have its own toString() method; it overrides the toString() method of the Object class. [![Image 4: Java ArrayList](#) Java ArrayList](#)
← Python3 Att Dictionary In HtmlPython3 Att Dictionary Clear β†’