This program also creates an ArrayList called "numbers" and adds some integers to it.

 It then uses a for loop to iterate through the ArrayList, and compares each element to

 the current smallest element. If a smaller element is found, it

 is assigned to the variable "smallest". Finally, the smallest element is printed to the console.


 import java.util.ArrayList;


public class SmallestElementArrayList {

    public static void main(String[] args) {

        ArrayList<Integer> numbers = new ArrayList<>();

        numbers.add(3);

        numbers.add(2);

        numbers.add(5);

        numbers.add(1);

        numbers.add(4);


        int smallest = numbers.get(0);

        for (int i = 1; i < numbers.size(); i++) {

            if (numbers.get(i) < smallest) {

                smallest = numbers.get(i);

            }

        }

        System.out.println("Smallest element in the ArrayList is: " + smallest);

    }

}

Here is a simple java program for apache kafka consumer. This java program is ready to use in your code base or project.
 import java.util.Collections; 
import java.util.Properties; 
 import org.apache.kafka.clients.consumer.ConsumerConfig; 
import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.consumer.ConsumerRecords;
 import org.apache.kafka.clients.consumer.KafkaConsumer;
 public class KafkaConsumerExample {

 public static void main(String[] args) {

 Properties props = new Properties();
 props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(ConsumerConfig.GROUP_ID_CONFIG, "myGroupId"); props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");

 KafkaConsumer consumer = new KafkaConsumer<>(props);
 consumer.subscribe(Collections.singletonList("myTopic")); 

 while (true) {
 ConsumerRecords records = consumer.poll(100); 
 for (ConsumerRecord record : 

records) { 

 System.out.println(record.value()); 
 } 
 } 
 } 
}

This example assumes that Kafka is running on the local machine at port 9092, 
 continuously poll for new messages on the topic and print the value of each message it receives.

Note that for production use, you should consider adding error
 handling and offset committing logic to the consumer code.