Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Articles - Page 139 of 745
2K+ Views
To find the IP Address of the client, the Java code is as follows −Example Live Demoimport java.net.*; import java.io.*; import java.util.*; import java.net.InetAddress; public class Demo{ public static void main(String args[]) throws Exception{ InetAddress my_localhost = InetAddress.getLocalHost(); System.out.println("The IP Address of client is : " + (my_localhost.getHostAddress()).trim()); String my_system_address = ""; try{ URL my_url = new URL("http://bot.whatismyipaddress.com"); BufferedReader my_br = new BufferedReader(new InputStreamReader(my_url.openStream())); my_system_address = my_br.readLine().trim(); } ... Read More
2K+ Views
You are given a String, your task is to write a program in Java that checks the order of its characters. If the order is previously defined, you have to check if the characters are in the given order otherwise check for alphabetical order. Let's understand the problem statement with an example − Example Scenario: Input: str = "abcmnqxz"; Output: res = TRUE The given string is in alphabetical order. Using Iteration In this approach, use a for loop to iterate over the string and check if the value of character at the current place and the previous ... Read More
2K+ Views
In this article, we will learn to print common characters of two strings in alphabetical order using Java. The program uses arrays to count how often each letter appears in both strings and then compares these counts to identify the common characters. Problem Statement Write a Java program to print common characters of two strings in alphabetical order − Input my_str_1 = "itsasample" my_str_2 = "thisisasample" Output The common characters between the two strings in alphabetical order is :aaeilmpsst Steps to print common characters of two strings in alphabetical order Following are the steps to print common characters of two strings ... Read More
685 Views
To find the second most repeated word in a sequence in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{ static String second_repeated(Vector my_seq){ HashMap my_map = new HashMap(my_seq.size()){ @Override public Integer get(Object key){ return containsKey(key) ? super.get(key) : 0; } }; for (int i = 0; i < my_seq.size(); i++) my_map.put(my_seq.get(i), my_map.get(my_seq.get(i))+1); int first_val = Integer.MIN_VALUE; int sec_val ... Read More
280 Views
To find the uncommon values concatenated from both the strings in Java, the code is as follows −Example Live Demoimport java.util.*; import java.lang.*; import java.io.*; public class Demo{ public static String concat_str(String str_1, String str_2){ String result = ""; int i; HashMap my_map = new HashMap(); for (i = 0; i < str_2.length(); i++) my_map.put(str_2.charAt(i), 1); for (i = 0; i < str_1.length(); i++) if (!my_map.containsKey(str_1.charAt(i))) result += str_1.charAt(i); else ... Read More
4K+ Views
In this article, we will learn to display the Hostname and IP address using Java. To display the Hostname and IP address we will be using the InetAddress class from the java.net package. We’ll write a simple program to fetch and print this information, and perform the exception handling to catch the exception if the data isn't found. Problem Statement Write a program in Java to display the Hostname and IP address. Below is a demonstration of the same − Output The IP address is : 127.0.0.1The host name is : jdoodle Steps to display Hostname and IP address Following are ... Read More
406 Views
To find the maximum and minimum element’s position in a list, the Java program is as follows −Example Live Demoimport java.util.*; import java.util.Arrays; import java.util.Collections; public class Demo{ public static int index_val(int my_arr[], int t){ if (my_arr == null){ return -1; } int len = my_arr.length; int i = 0; while (i < len){ if (my_arr[i] == t){ return i; } else { ... Read More
623 Views
To iterate over a Stream with Indices in Java 8, the code is as follows −Example Live Demoimport java.util.stream.IntStream; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; public class Demo{ public static void main(String[] args){ String[] my_array = { "T", "h", "i", "s", "s", "a", "m", "p", "l", "e" }; AtomicInteger my_index = new AtomicInteger(); System.out.println("The elements in the string array are :"); Arrays.stream(my_array).map(str -> my_index.getAndIncrement() + " -> " + str).forEach(System.out::println); } }OutputThe elements in the string array are : 0 -> T 1 -> h 2 -> i 3 ... Read More
1K+ Views
In this article, we will learn to print unique values from a List in Java. This program will use a loop-based approach to identify and display only the values that appear once, skipping any duplicates. This approach is helpful when working with datasets where you want to remove repeated items and focus on distinct entries. Problem Statement Write a program in Java to print unique values from a list. Below is a demostration of the same − Input 55, 67, 99, 11, 54, 55, 88, 99, 1, 13, 45 Output The distinct elements in the array are 55 67 99 11 ... Read More