import java.util.LinkedList;
import java.util.ListIterator;
import java.io.*;
public class llist {


    public static void main(String[] args) {
        String abc="poo";
        String[][] array_string;
        array_string= new String[10][10];
        array_string[0][0]="123";
        for(int i=0;i<5;i++){
            for(int j=0;j<5;j++){
                array_string[i][j]=(String)j;
                System.out.print(array_string[i][j]);
                System.out.println("");

            }
        }
    }

}

error is:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Cannot cast from int to String

    at llist.main(llist.java:14)

question is:
I want to display numbers in the string array(2D array)?

To do that you must convert the ints to Strings. You can use the toString(int i) method in the Integer class.

Yes I think he means..
Integer.toString(int i)..

Or just write ""+i, this will create a String of the number, thats what I would do.

@cms271828
Yes, I know exactly what I meant. I deliberately gave the OP just enough info for him to look it up himself, thus getting essential practice in working the API JavaDoc. By giving him the actual code he can just copy/paste and learn nothing.

""+i is a judgement call. That's what I would do in my own code, but it's not helpful to just put it in front of a newbie without any explanation. I took the view that the explanation was likely to be confusing and unhelpful at this stage; and I certainly wasn't going to post it as some kind of magic formula.

It's always difficult to know how far to go in giving help or solutions.

I never said you didn't know what you meant, I just said I think I know what you meant.
Then I gave an alternative.
Cause I thought you may of meant, wrap the int into an Integer...
Integer xObj = new Integer(x);
Then, xObj.toString() [using toString() implementation from toString() in Object class].

So I think its wise to know about toString in Object class and how its implemented in subclasses as well as overloaded versions like the one you mentioned.

But as you gave a parameter, it must have been the static toString method that you meant, which is what I was trying to point out in my post

Hi @cms271828.
OK, I don't think we have any real disagreement here, and we shouldn't hijack the OPs thread anyway. I just wanted to encourage the OP top practice his API Javadoc skills.
It's cool.
J

ok guys i got what both were discussing in the post.
Thanks .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.