-3

I've got lots of data stored like this

["5368","45946","532.3602831594635","8.559239940387481"]

That I have to iterate over.

What is the most efficient way to access these variables?

Currently I'm deserializing into a List> however and accessing get(0).get(0) or whatever, but it's slow on big amounts of data.

beek
  • 3,522
  • 8
  • 33
  • 86
  • Sorting and searching. – Juned Ahsan Jun 10 '15 at 00:25
  • Is it one-way list? – Ediac Jun 10 '15 at 00:25
  • possible duplicate of [Ways to iterate over a List in java?](http://stackoverflow.com/questions/18410035/ways-to-iterate-over-a-list-in-java) – Jean-François Savard Jun 10 '15 at 00:27
  • Just access each value. Currently I'm deserializing into a List> however and acessing get(0).get(0) or whatever, but it's slow on big amounts of data. – beek Jun 10 '15 at 00:33
  • What kind of `List`? If it's a `LinkedList`, then using `.get(n)` is a linear operation, and will be slow for large lists. You could change the underlying type to an `ArrayList` which is constant time for `.get(n)`, or alternatively use an `Iterator`. – clstrfsck Jun 10 '15 at 01:04

2 Answers2

1

It may be faster using JAVA8 Stream and parallel forEach.

    List<List<String>> list = new ArrayList<>();
    // .....
    list.stream().parallel()
        .forEach(sublist -> sublist.stream().parallel()
             .forEach(element -> /* do something to element */));
0

Possible duplicate of Why would iterating over a List be faster than indexing through it? Iterating is quite simple, but what you'll do when iterating is more relevant to speed efficiency.

Community
  • 1
  • 1
Christophe Douy
  • 813
  • 1
  • 11
  • 27