Char Array ib Java?

Reply

Join Date: Feb 2009
Posts: 22
Reputation: shahab.burki is an unknown quantity at this point 
Solved Threads: 0
shahab.burki shahab.burki is offline Offline
Newbie Poster

Char Array ib Java?

 
0
  #1
Feb 18th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Char Array ib Java?

 
0
  #2
Feb 18th, 2009
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 22
Reputation: shahab.burki is an unknown quantity at this point 
Solved Threads: 0
shahab.burki shahab.burki is offline Offline
Newbie Poster

Re: Char Array ib Java?

 
0
  #3
Feb 18th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Char Array ib Java?

 
0
  #4
Feb 18th, 2009
That depends on what you mean by "manipulate".
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Char Array ib Java?

 
0
  #5
Feb 18th, 2009
Originally Posted by shahab.burki View Post
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?

  1. char [] row = new char[5]; // is the same as any other array declaration
  2. for ( int i = 0; i < row.length; i++)
  3. row[i] = 'A';
  4. // now you have your {'A','A'...} do notice that for chars, you don't use ", but '
  5. // to manipulate the first char of the row (set the value to 'B')
  6. row[0] = 'B';
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC