Results 1 to 3 of 3
Thread: Array of Char's
- 05-24-2012, 02:58 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Array of Char's
Hi All,
I am having difficulty to understand the difference between:
andJava Code:char [] myOriginalArray = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'};
Why eclipse wont compile the second but will compile the first one.........Java Code:char [] myOriginalArray; myOriginalArray = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'};
both are exactly the same to me.
any thought????
Tariq
- 05-24-2012, 03:14 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,372
- Blog Entries
- 7
- Rep Power
- 17
Re: Array of Char's
The first form is an array initialization, while the second form is an assignment and the compiler doesn't know what its type is; you think you can see that its an array of chars, but to the compiler it can also be an array of doubles, or longs, or ints. Because it is ambiguous to the compiler it doesn't allow it. You can do this though:
kind regards,Java Code:myOriginalArray = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'};
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-24-2012, 03:56 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
convert byte array into char array
By kgkamaraj in forum New To JavaReplies: 4Last Post: 09-13-2011, 11:32 AM -
searching char array with another char array for full word matches
By karunabdc in forum New To JavaReplies: 2Last Post: 03-08-2011, 06:20 AM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
array of char
By sinisab in forum New To JavaReplies: 9Last Post: 01-05-2010, 09:48 AM -
Convert Char Array to String Array
By Mayur in forum New To JavaReplies: 8Last Post: 10-12-2009, 11:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks