• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

ArrayList<String> to int.  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello. I have some problems with this code. This is seafight from Java HeadFirst. How I notice ArrayList is massive which contain list of Strings, not ints and this causing a problem:

SimpleDotComGame.java:46: error: incompatible types: int[] cannot be converted
o ArrayList<String>
       theDotCom.setLocationCells(locations);

I have tried to put this code but I created only even more errors, because I dont understand how call this method in my original code:

;  

Can someone explain to me how can I unite ArrayList<String> with int []? Sorry for vague explanation.
 
Saloon Keeper
Posts: 10211
216
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To convert an int[] to a List<String>, I would first use Arrays.stream(), and then IntStream.mapToObj() and Stream.collect().

However, I'm not convinced that you need either type. If you are interested in integers, you can make DotCom hold a List<Integer>, and pass a Collection<Integer> when you construct an instance.
 
Ranch Hand
Posts: 483
23
AngularJS Eclipse IDE Firefox Browser Java Spring VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Harold,a warm welcome to javaRanch.

your code is quite confusing.taking too much time to understand,try to write indently along with comments explaining what you are doing or wants to do.

in your case you should use ArrayList<Integer> instead of ArrayList<String> and you have also gave wrong argument type to method setLocationCells give the argument as Arrays.asList(locations) to method or simply use ArrayList<Integer> instead of array.

Thankyou,

kind Regards,
praveen.
 
Marshal
Posts: 64493
225
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also never write == true or == false. Both are poor style and error‑prone; you might write = instead of == by mistake.
Never
while (b == true) ...
always
while (b) ...
Never
while (b == false) ...
always
while (!b) ...

And welcome again
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!