0

This is the code in Python I'm trying to convert to Java:

self.active = set(self.genes[-self.output_length:]):

Reading up on the sets in Python, I believe that this is splitting the ArrayList at the index of 'self.output_length'. Is this correct? A little background: the 'self.genes' contains genes which present both 'self.output_length' and 'self.nodes'.

Could I used this in Java:

List<float[]> temp = this.genes.subList(0,this.output_length);
this.active = Set(Collections.reverse(temp));

UPDATE: As per a previous answer, I've now done this:

List<float[]> temp = this.genes.subList(this.genes.size() - this.output_length, this.genes.size()); 
this.active = new ArrayList<float[]> (temp);

Thanks for your help.

1
  • Could anyone point me to some documentation on the [-n:]? I've tried to look under docs.python.org/2/library/re.html, but can't figure it out. thanks Commented Jul 30, 2013 at 22:22

1 Answer 1

0

If you want to use an ordered set in Java, use one of implementations of SortedSet. You need not to reverse the order of List before filling the Set, as it has no effect. To provide required ordering, pass a Comparator to the Set's implementation constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.