Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Arrays.toString(String[]) method

 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using Arrays.toString(String[]) method to display the information in logs. But I am getting an error like 'the method toString() in the type object is not applicable for the arguments(String[])' in eclipse, when I use this method. What is the wrong with this?

Regards,

Shashi Kala
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shashi,

it's difficult to tell you the exact problem without knowing the bit of code which makes you trouble. Anyway the Arrays.toString() methods need one parameter which has to be an array of some type. Are your "log entries" arrays of string or what? Take a look at the )]API doc then you can surely figure it out yourself

Marco
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The toString methods have only been added in Java 5.0. If you are using Java 1.4 or below, there is only one toString() method and that's the one inherited from Object. And that isn't static of course.
 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,

See the code here I am using.

Where obj.getIDs() returns string array. printLog() method takes the arguments string,string. meth variable also a string.


Here in first line eclipse is showing me an error.
 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and one more thing..

I am using java 1.4 version. But Arrays.toString() is since 1.5 version right? then is there any way to get the same work done?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shashi,

I think you can do two things to get this done:

1) Use Java >= 1.5 if possible.

2) Write your own helper class/method which takes your array of Strings and returns a concatenated String containing all the Strings of the array. I think this wouldn't be to difficult.

Marco
 
Shashi Kala
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,

I did the second thing..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic