Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Unique Values in ArrayCollection?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, I am new to Java so this may seem like a basic question. Second, I am new to JavaRanch and this may not be the correct forum. With that...

I have a need to export data to a CSV file and have been able to find a small servlet that does the trick. However I need to find the unique values in one of the columns. Specifically one of the columns is "Timeline" and it displays the date. But I would like to find the unique values of the timeline column in order to change the format of the output.

So, what's the best approach for finding the unique values? I have to use ArrayCollection (I think) because this is being passed from a Flex application. Based on the code snippet below, is there a way to get the unique values for Timeline based on the HashMap that is created? I get confused on all the different types such as HaspMap, Set, etc.

Thanks,
Rob



Code Snippet:

public String[] getData(ArrayCollection arrayCollection) {
Object[] elements = arrayCollection.toArray();
int rows = elements.length;
String[] results = new String[rows + 1];
StringBuffer result = new StringBuffer(1000);

// Loop through the array
for (int i = 0; i < rows; i++) {
//The column names and values are stored in a HashMap for each row
map = (HashMap)elements[i];

< AND SO ON to loop through and build a CSV string>
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayCollection is an ActionScript class, there is no class of that name in Java. The equivalents in Java would be an array, or some suitable Collection (such as an ArrayList).

One of the easiest ways of removing dublicates is to add them to a Set. Sets don't support duplicates, so these will go. And its easy to transfer from one Collection to another. You just need to make sure your possible unique object has an equals() method that matches your uniqueness requirement.

 
Robert Jones
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi - thanks for the quick reply and pointing out that ActionScript class.

I'll check on implementing the Set you referred to.
 
reply
    Bookmark Topic Watch Topic
  • New Topic