Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:So please tell me how do i then copy the elements of ArrayList into a String array?>
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
However, I'm not sure why you think you need to convert the contents to an array at all.
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:By the way, Winston i tried what you suggested and im still getting that ClassCastException error
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Are you referring to here? the ArrayList variable name?and BTW, it should be a List<String> anyway.
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:Dear all,
Before asking this question i have already checked this forum for question similar to this and have concluded that the only method to be able to copy an ArrayList into a String Array is to iterate through the ArrayList and then use the get method but i'm unable to do so?
Koushik Ghosh wrote:He's trying to tell you to instantiate the arraylist like this :
I'm not quite sure whether this is the root of the exeption, but try it anyway. If problem persist then let us know.
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:So the updated code with kind corrections from Winston and Koushik clarifying it for me is as follows, but like i posted earlier, this code is now throwing NullPointerException at line 41
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Ashish Dutt wrote:So the updated code with kind corrections from Winston and Koushik clarifying it for me is as follows, but like i posted earlier, this code is now throwing NullPointerException at line 41
Why is 'list' defined as static? I'm not sure if that's the problem, but it's sure as hell NOT a good idea.
Winston
Ashish Dutt wrote:So the updated code with kind corrections from Winston and Koushik clarifying it for me is as follows, but like i posted earlier, this code is now throwing NullPointerException at line 41
Koushik Ghosh wrote:here you don't need to return the list. modify the return type as void. When you modify list in the method the global variable (list) is modified. When you access the list from another method you get the modified list.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:So the updated code with kind corrections from Winston and Koushik clarifying it for me is as follows, but like i posted earlier, this code is now throwing NullPointerException at line 41
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:But you will hate to know that when i ran the above code it failed with the same ClassCastException.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Ashish Dutt wrote:But you will hate to know that when i ran the above code it failed with the same ClassCastException.
You haven't been reading your replies. If you look back, you'll see that I said you need to use toArray(T[] array) - and I even showed you how to do it. toArray() returns an Object[]; and in the case of ArrayList, it really IS an Object[].
Winston
Then you can get a string array by using toArray(String[]), viz:
String[] dump = list.toArray(new String[0](new String[0]));
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:Awesome, I carefully re-read your previous post again and rectified the problem
This call's for a standing ovation, Thank you very much Winston. Cheers.
Now, just do me one more favour, can you please explain to me what is the meaning of this sentence from your post
Then you can get a string array by using toArray(String[]), viz:
String[] dump = list.toArray(new String[0](new String[0]));
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
This method acts as bridge between array-based and collection-based APIs. (from Oracle docs)
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:Do correct me if this interpretation is wrong.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
But just to make sure you understand completely: Why supply a 0-length array?
Winston
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:There you caught me red handed.... :-( Now this answer is a fluke. Maybe because we want the String [] dump array to resize itself automatically according to the size of the ArrayList... ?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
Ashish Dutt wrote:Thanks again Winston, for leveraging confidence in my otherwise skeptical cloud of thoughts.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Well THAT's new! Comfort me, reliable tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|