# list « algorithm « Java Collection Q&A

Home
Java Collection Q&A
 1 algorithm 2 array 3 Array Byte 4 Array Char 5 Array Convert 6 Array Dimension 7 Array Integer 8 Array Object 9 Array String 10 ArrayList 11 collection 12 comparator 13 Development 14 Garbage Collection 15 Generic 16 hash 17 HashMap 18 HashTable 19 iterator 20 LinkedList 21 List 22 Map 23 queue 24 Set 25 Sort 26 tree
 Java Collection Q&A » algorithm » list

### 1. How to find intersecting periods in a huge list of periods?    stackoverflow.com

I need an idea for an efficient index/search algorithm or datastructure for a particular problem. So far I could not come up with something fast and elegant... Consider a huge collection of ...

### 2. Efficient look-up in a List    stackoverflow.com

I have a situation whereby I'm populating an `ArrayList` with "`TransactionEvent`"s. `TransactionEvent` has a property "transaction ID". In the large majority of cases each new event has a transaction ...

### 3. Simple Java List Question    stackoverflow.com

I am supposed to create an iterative method stretch that takes a positive number n as a parameter and returns a new ListItem beginning a list in which each of the ...

### 4. Fastest way to pick a random element from a list that fulfills certain condition    stackoverflow.com

I need to pick a random element from a list, that fulfills certain condition. The approach I've been using works, but I'm sure is not every efficient. What would be the ...

### 5. Count all lists of adjacent nodes stored in an array    stackoverflow.com

There are many naive approaches to this problem, but I'm looking for a good solution. Here is the problem (will be implemented in Java): You have a function foo(int a, int b) ...

### 6. Find common nodes from two linked lists using recursion    stackoverflow.com

I have to write a method that returns a linked list with all the nodes that are common to two linked lists using recursion, without loops. For example, first list is 2 ...

### 7. Efficient priority list    stackoverflow.com

I am looking for an efficient data structure to represent a priority list. Specifically I need to assign a priority to a set of items and return only the top scoring ...

### 8. Java: Using adjacency list to compute all pairs shortest path?    stackoverflow.com

I am writing a Graph library that has both adjacency list and matrix implementations. Here is some code I came across in a Java data structures textbook:

``````static void floyd(Graph<V,E> g)
// ...``````

### 9. Sequentially distribute data from a list to arrays of different weight    stackoverflow.com

How to, Sequentially distribute data from a list to arrays (or some other structure) of fixed size/weight. For example, lets say I have a list of 10 elements. I want to sequentially ...

### 10. Best algorithm for comparing a base coordinate to a list of n coordinates and determining the closest m coordinates?    stackoverflow.com

I have some code doing this right now. It works fine with small to medium sized lists, but when I have a list of size n > 5000 then the my ...

### 11. A faster way to compare lists for a common element in Java?    stackoverflow.com

I have a graph (implemented with Vector) of LinkedLists and I want to connect the LinkedLists that do not share any common elements. I think the way I do it right ...

### 12. Generating a non-repeating list of alpha-numeric codes    stackoverflow.com

I'm trying to generate a list of non-repeating alpha-numeric codes. They will be generated in batches and in volumes such that it won't be feasible to explicitly look at what has ...

### 13. Take n random elements from a List?    stackoverflow.com

How can I take n random elements from an `ArrayList<E>`? Ideally, I'd like to be able to make successive calls to the `take()` method to get another x elements, without ...

### 14. List all possible combinations    stackoverflow.com

Here's what I am trying to do:

Given a list of names, print out all combinations of the names taken three at a time. If the list ...

### 15. java - How to find matching objects between two lists?    stackoverflow.com

Given two Lists, each list holding the same object type, I would like to find objects between the two lists that match, based on some property values. e.g. an object from List1, ...

### 16. Algorithm: Locates an element in a list of increasing integers by splitting the list into four subsists     stackoverflow.com

Stuck on homework: I need help making this Algorithm!!! Algorithm: Locates an element in a list of increasing integers by successively splitting the list into four subsets of equal (or close ...

### 17. List items ordering problem    stackoverflow.com

I have a list of items and set of users. Users can re-order list items. Each user has his own view for the list, he can arrange the items in his ...

### 18. How to get a list of all lists containing exactly one element of each list of a list of lists    stackoverflow.com

As you may have understood with the title, I need some smart thinking here :) I have a `List<List<Object>>` object. If you think of the Object objects as integers, you could see ...

### 19. Java algorithm to slice a list    stackoverflow.com

I'm trying to slice a list (call this input list & it contains Java double data type elements) in multiple parts (sub lists). The size of the sub lists can be ...

### 20. How to expose a dynamic list of method calls in Java?    stackoverflow.com

How would you suggest going about implementing the following scenario. I have a few thoughts, but none that satisfies my problem in totality, so I would like to get your input. I ...

### 21. How to avoid O(N^2) when comparing elements from 2 lists?    stackoverflow.com

I have 2 lists with same Object type.

``````List A [ foo, bar, moo, woo, pee ]

List B [ bar, woo ]
``````
I want to compare those 2 lists and if the name ...

### 22. BinarySearch does not find element in list even when it's there : Java    stackoverflow.com

Can anyone point out where I've gone wrong here? I stepped through it with a debugger and it looks like my algorithm should be finding the search key, but its not. ...

### 23. Transforming a LinkedHashSet into a List    stackoverflow.com

I want to apologize for my english because I'm French. Let's say the List b is a LinkedList. Let's say the List a is also a LinkedList. How do I append these list in ...

### 24. Extracting top recommendations from multiple recommendation lists    stackoverflow.com

I have four lists of recommendations and lets say the lists are A,B,C,D. Every list has the same number of items and are represented as key-value pairs. But I need to give ...

### 25. Java: Difference between two lists    stackoverflow.com

My company's cat-herding application tracks a convoy of cats. Periodically, it needs to compare `previousOrder` to `currentOrder` (each is an `ArrayList<Cat>`) and notify the cat-wranglers of any changes. Each cat is ...

### 26. Searching amongst a list of strings    stackoverflow.com

I have a list of article names which are strings, and based on a user query, I need to output a best search out of that list of article names. I ...

### 27. Approximate searching against a list of strings    stackoverflow.com

So yes, I read about how edit distance can be used between strings to decide how "close" are two string to each other. This algorithm, implemented as a Dynamic problem takes ...

### 28. how to create a list of tuples from each value within a set of lists    stackoverflow.com

I'd like to create a list of tuples from each value within a set of lists. The set of lists can be open, but for the example I have the following ...

### 29. Given a list of items (different types), how do I separate those, so that each group contains only items with the same type    stackoverflow.com

Given a `List` of items of different types, how do I efficiently separate those, so each group only contains item of the same type? `More details` In java, I have a `List` ...

### 30. Combining like items in a List    stackoverflow.com

I saw an earlier post which is trying to do a similar sort of thing in Python. Here is a boiled down example of what I want. Let us say ...

### 31. Printing all possible subsets of a list     stackoverflow.com

I have a List of elements (1, 2, 3), and I need to get the superset (powerset) of that list (without repeating elements). So basically I need to create a List ...