How to terminate the currently running program in Java

1 Answer

0 votes
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
 
public class MyClass
{
    public static void main(String[] args)
    {
        List<String> list = Arrays.asList("java", "c", "c++", "rust", "python", "cobol");
 
        List<String> filteredList = new ArrayList<>();
  
        for (String s: list) {
            if (s.startsWith("c")) {
                filteredList.add(s);
                System.exit(0);
            }
        }
  
        System.out.println(filteredList);
    }
}
 
 
 
 
/*
run:
 

 
*/

 



answered Mar 20, 2023 by avibootz

Related questions

4 answers 264 views
1 answer 272 views
1 answer 79 views
1 answer 123 views
...