Skip to content

Instantly share code, notes, and snippets.

@eroltutumlu
Created March 4, 2015 21:30
Show Gist options
  • Save eroltutumlu/1bdffbd86174de99001a to your computer and use it in GitHub Desktop.
Save eroltutumlu/1bdffbd86174de99001a to your computer and use it in GitHub Desktop.
Simple java Collections sample
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