Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
can you please sort the error??
Deepakk Verma
Ranch Hand
Posts: 31
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am having error in the program can anybody help please
public class StringDemo2 { public static void main(String args[]) { String strob[] = new String[4]; String alpha = "abcdefgh"; for(int i=0; i<4;i++) { strob[i] = alpha.charAt(i); } } }
Error is in 7th line as:
Type mismatch: cannot convert from char to
String
Maneesh Godbole
Bartender
Posts: 11497
19
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
As the error indicates, String#charAt returns a char, which you are trying to put in an array, designed for Strings
You need to convert the char to a String. Check out the String API for a convenient method.
PS. Also check out String#substring()
[
How to ask questions
] [
Donate a pint, save a life!
] [
Onff-turn it on!
]
Deepakk Verma
Ranch Hand
Posts: 31
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
OOPS.....i should have taken care of that ............Thanks Maneesh
Just the other day, I was thinking ... about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Random Class........Problem
array!
Question on Integer type
Garbage Collection and String Literals
More...