java - Why doesn't this if statement work properly? -


i'm trying remove in array have has more 7 letters , less 5.

the program runs doesn't remove words have more 7 letters , less 5 letters.

i have used iterator read array, seems ignores if statement

iterator<string> = muligeord.iterator(); while (it.hasnext()) {     if(it.next().length()<=5 && it.next().length()>=7){         it.remove();     } } 

okay, have 2 major issues in 1 line

if(it.next().length()<=5 && it.next().length()>=7){ 

.next() move curser, since using &&, if length of object <= 5, next call move curser next object in collection; not want.

if is not want, , want chacking same object, how can length both >7 , <5 @ same time?

try using this, move curser once , object, change && ||, remove not 6 characters in length.

string = it.next(); if( something.length() <= 5 || something.length() >= 7 ) {     it.remove(); } 

in post

the program runs doesn't remove words have more 7 letters , less 5 letters.

to me, means want keep has 5, 6, or 7 characters; again if case, need change <=s <.

string = it.next(); if( something.length() < 5 || something.length() > 7 ) {      it.remove(); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -