Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way I can print String array without using for loop? [duplicate]

Is there any function in java like toString() to print a String array?

This is a silly question but I want to know if there is any other way than writing a for loop.

Thanks.

like image 833
priyank Avatar asked Aug 14 '10 00:08

priyank


People also ask

How do you print a string array without loop?

Pseudo Code:println(Array[i]); Concept: We will be using the toString() method of the Arrays class in the util package of Java. This method helps us to get the String representation of the array. This string can be easily printed with the help of the print() or println() method.

How do I print non duplicate elements in an array?

Finding the non repeating element in an array can be done in 2 different ways. Method 1: Use two loops, one for the current element and the other to check if the element is already present in the array or not. Method 2: Traverse the array and insert the array elements and their number of occurences in the hash table.


2 Answers

String[] array = { "a", "b", "c" }; System.out.println(Arrays.toString(array)); 
like image 57
Mike Avatar answered Sep 20 '22 17:09

Mike


With Apache Commons Lang,

System.out.println(StringUtils.join(anArray,",")); 
like image 23
TheLQ Avatar answered Sep 20 '22 17:09

TheLQ