diff -r 38b7cb606a05 -r 6045bfdd65a5 jdk/src/java.base/share/classes/java/util/Arrays.java --- a/jdk/src/java.base/share/classes/java/util/Arrays.java Fri Apr 29 13:24:27 2016 +0300 +++ b/jdk/src/java.base/share/classes/java/util/Arrays.java Fri Apr 29 16:52:05 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4403,6 +4403,35 @@ public void sort(Comparator c) { Arrays.sort(a, c); } + + @Override + public Iterator iterator() { + return new ArrayItr<>(a); + } + } + + private static class ArrayItr implements Iterator { + private int cursor; + private final E[] a; + + ArrayItr(E[] a) { + this.a = a; + } + + @Override + public boolean hasNext() { + return cursor < a.length; + } + + @Override + public E next() { + int i = cursor; + if (i >= a.length) { + throw new NoSuchElementException(); + } + cursor = i + 1; + return a[i]; + } } /**