Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Array list which contains events
Angus Ferguson
Ranch Hand
Posts: 1402
3
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have the next code for listing the content of an arrayList.
public class ListEventsCity { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here ArrayList<String> listItem = new ArrayList<String>(); listItem.add("Sunday"); listItem.add("Monday"); listItem.add("Tuesday"); /* * To convert ArrayList containing String elements to String array, use * Object[] toArray() method of ArrayList class. * * Please note that toArray method returns Object array, not String array. */ //First Step: convert ArrayList to an Object array. Object[] objItem = listItem.toArray(); //Second Step: convert Object array to String array String[] strItem = Arrays.copyOf(objItem, objItem.length, String[].class); System.out.println("ArrayList converted to String array"); //print elements of String array for (int i = 0; i < strItem.length; i++) { System.out.println(strItem[i]); } } }
I would like to list events which currently are happening in a city. Is possible to connect with a feed API or another possible solution?
Regards, Isaac
Charles D. Ward
Ranch Hand
Posts: 99
1
posted 8 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Your ArrayList doesn't contain Events, it contains Strings.
Why are you converting it to an Object array and then to a
String
array? Why not just print out the Strings directly from the ArrayList?
Campbell Ritchie
Marshal
Posts: 79177
377
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can even get the List to print out and give you a nice display:-
[Sunday, Monday, Tuesday]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Convert generic ArrayList to array of specific type
iterate over a list and get values from a object?
Problem: ArrayList with For loop
casting of an ArrayList
behavior of switch statement with enums
More...