0

This is my code:

a1 = Splitter.fixedLength(4).split("goodgirl");
System.out.println("a1=" + a1);
a3[1] = a1.iterator().next();
System.out.println("a3[1]=" + a3[1]); 

When I use Splitter class from Guava library, my string i.e. "goodgirl" gets split into [good, girl] as fixed length is 4 and gets stored in a1.

Now with a3[1] = a1.iterator().next(); I can get the substring "good" from a1.

How can i get the next substring (i.e. "girl")?

Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
mkr
  • 1
  • 2

1 Answers1

0

EDIT

Or use Iterables.get(Iterator, 1);

Iterator<String> iterator = Splitter.fixedLength(4).split("goodgirl").iterator();
            while(iterator.hasNext()){
                System.out.println(iterator.next());
            }

next() return the next token, you should use it with hasNext

Eugene
  • 117,005
  • 15
  • 201
  • 306
  • hasNext() Returns true if the iteration has more elements. But i need a method that returns second element. As i can get first element with iterable.iterator().next(); – mkr Sep 02 '14 at 09:01
  • 1
    @mkr since you have guava: Iterables.get(iterator, 1); – Eugene Sep 02 '14 at 09:13
  • And one more thing, has.next() is leading me to infinite loop, to stop it i need to use endOfData(). Can you help me? (Means the syntax.) @Eugene – mkr Sep 02 '14 at 09:22