0

Hi,

Can we declare Char Array in Java instead of String Arrays? So we can manipulate them? or we have to use Strings and then use charAt() method for it?

Thanks

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by stultuske
0

Of course you can declare char arrays, but be aware that each "String" is a char array, so you would need a two dimensional array to hold char arrays equivalent to an array of Strings.

0

I understan that. What I cann,t understand is showing throgh example. For Example I am going to store char's "A A A A A" in array. for some reasons I want to manipulate it later then how can I do that?

Thanks

0

I understan that. What I cann,t understand is showing throgh example. For Example I am going to store char's "A A A A A" in array. for some reasons I want to manipulate it later then how can I do that?

Thanks

where lies the problem? in declaring the array and filling it?

char [] row = new char[5]; // is the same as any other array declaration
for ( int i = 0; i < row.length; i++)
  row[i] = 'A';
// now you have your {'A','A'...} do notice that for chars, you don't use ", but '
// to manipulate the first char of the row (set the value to 'B')
row[0] = 'B';
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.