Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a class to hold your data objects:</p> <pre><code>private static final class Data { private final BigDecimal point; private final Date date; public Data(final String point, final String date) { this.point = new BigDecimal(point); this.date = new Date(Long.parseLong(date)); } @Override public String toString() { return "Data{" + "point=" + point + ", date=" + date + '}'; } } </code></pre> <p>Now parse the string using a regex pattern, building the <code>Data</code> objects as you go. I have used possessive matchers as the <code>String</code> is presumably quite long and you don't want the express engine to backtrack along it repeatedly trying to match.</p> <p>The <code>Data</code> can, as here, even parse the individual <code>String</code>s to the real data types.</p> <pre><code>public static void main(String[] args) { final String s = "[14.1,1363649400],[14.4,1363650300],[14.6,1363651200],[15.1,1363652100],[14.3,1363653000],[14.2,1363653900],[14.8,1363654800]"; final Pattern p = Pattern.compile("\\[([^,]++),(\\d++)\\]"); final Matcher matcher = p.matcher(s); final Collection&lt;Data&gt; datas = new LinkedList&lt;Data&gt;(); while (matcher.find()) { datas.add(new Data(matcher.group(1), matcher.group(2))); } for (final Data data : datas) { System.out.println(data); } } </code></pre> <p>Output:</p> <pre><code>Data{point=14.1, date=Fri Jan 16 19:47:29 GMT 1970} Data{point=14.4, date=Fri Jan 16 19:47:30 GMT 1970} Data{point=14.6, date=Fri Jan 16 19:47:31 GMT 1970} Data{point=15.1, date=Fri Jan 16 19:47:32 GMT 1970} Data{point=14.3, date=Fri Jan 16 19:47:33 GMT 1970} Data{point=14.2, date=Fri Jan 16 19:47:33 GMT 1970} Data{point=14.8, date=Fri Jan 16 19:47:34 GMT 1970} </code></pre> <p>Obviously you can put those <code>Data</code> into a <code>Map</code> or <code>Set</code> or whatever suits you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload