---
title: "Check if a List of integers contains only odd numbers?"  
description: "Check if a List of integers contains only odd numbers?"  
author: "Mukul Goenka"  
published: 2021-11-17  
canonical: https://www.mindstick.com/interview/33831/check-if-a-list-of-integers-contains-only-odd-numbers  
category: "java"  
tags: ["c#", "java", "programming language"]  
reading_time: 2 minutes  

---

# Check if a List of integers contains only odd numbers?

```
Program
```

```
import java.util.*;public class MyClass {    public static void main(String args[]) {      MyClass hw = new MyClass();         List<Integer> list = new ArrayList<Integer>();               //Adding elements in the List               list.add(11);               list.add(13);               list.add(15);               list.add(3);          if(hw.onlyOddNumbers(list))            System.out.println("List contain only odd number");    }     public static boolean onlyOddNumbers(List<Integer> list) {         for (int i : list) {             if (i % 2 == 0)             return false;         }     return true;     }}
```

Output.

List contain only odd number

## Answers

### Answer by Mukul Goenka

```
Program
```

```
import java.util.*;public class MyClass {    public static void main(String args[]) {      MyClass hw = new MyClass();         List<Integer> list = new ArrayList<Integer>();               //Adding elements in the List               list.add(11);               list.add(13);               list.add(15);               list.add(3);          if(hw.onlyOddNumbers(list))            System.out.println("List contain only odd number");    }     public static boolean onlyOddNumbers(List<Integer> list) {         for (int i : list) {             if (i % 2 == 0)             return false;         }     return true;     }}
```

Output.

List contain only odd number


---

Original Source: https://www.mindstick.com/interview/33831/check-if-a-list-of-integers-contains-only-odd-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
