954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Char Array ib Java?

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

shahab.burki
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 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.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

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

shahab.burki
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

That depends on what you mean by "manipulate".

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

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';
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You