How to use array variable defined outside main method in Java -
public class tostring { string mystr[] = {"a","b","c"}; public static void main(string[]args) { mystr[] mystr1 = new mystr[]; system.out.print(mystr.tostring()); } }
- make array variable static if wish use in static method.
- use
system.out.println(java.util.arrays.tostring(mystr));
if want see string representation makes sense. otherwise you're going see non-sense you. - get rid of line
mystr[] mystr1 = new mystr[];
doesn't make sense. - in future, please tell problems having code you've posted, including error messages might seeing. please go through tour, help , how ask question sections see how site works , improve current , future questions, can better answers.
Comments
Post a Comment