Created
March 4, 2015 21:30
-
-
Save eroltutumlu/1bdffbd86174de99001a to your computer and use it in GitHub Desktop.
Simple java Collections sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
List<String> list1 = new ArrayList<String>(); | |
Scanner scan = new Scanner(System.in); | |
System.out.println("Bir sayı yazınız : "); | |
int number = scan.nextInt(); | |
for(int i = 0; i < number; i++){ | |
System.out.println("String : "); | |
list1.add(scan.next()); | |
} | |
removeValue(list1); | |
printValue(list1); | |
} | |
public static void removeValue(Collection<String> listem){ | |
for(Iterator<String> list1 = listem.iterator(); list1.hasNext();) | |
if(list1.next().startsWith("as")) | |
list1.remove(); | |
} | |
public static void printValue(Collection<String> listem){ | |
for(String i:listem) | |
{ | |
System.out.println(i); | |
} | |
/* | |
for(Iterator<String> llem = listem.iterator(); llem.hasNext();) | |
System.out.println(llem.next()); | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment