Find Maximum and Minimum Element's Position in a List in Java

AmitDiwan
Updated on 07-Jul-2020 09:54:25

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

Iterate Over a Stream with Indices in Java 8

AmitDiwan
Updated on 07-Jul-2020 09:52:03

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

Sort Words of a Sentence in Ascending Order in Java

AmitDiwan
Updated on 07-Jul-2020 09:41:56

5K+ Views

To sort words of sentence in ascending order, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{    static void sort_elements(String []my_str, int n){       for (int i=1 ;i= 0 && temp.length() < my_str[j].length()){             my_str[j+1] = my_str[j];             j--;          }          my_str[j+1] = temp;       }    }    public static void main(String args[]){       String []my_arr = {"This", "is", "a", "sample"};       int len = my_arr.length;       sort_elements(my_arr,len);       System.out.print("The sorted array is : ");       for (int i=0; i

Split Even and Odd Elements into Two Different Lists in Java

AmitDiwan
Updated on 07-Jul-2020 09:16:21

848 Views

To split the Even and Odd elements into two different lists, the Java code is as follows −Example Live Demoimport java.util.Scanner; public class Demo{    public static void main(String[] args){       int n, j = 0, k = 0;       Scanner s = new Scanner(System.in);       System.out.println("Enter the number of elements required :");       n = s.nextInt();       int my_arr[] = new int[n];       int odd_vals[] = new int[n];       int even_vals[] = new int[n];       System.out.println("Enter the elements of the array(even and add numbers) ... Read More

Private Browsing Mode of Web Browsers

Samual Sam
Updated on 07-Jul-2020 09:16:12

392 Views

“Private Browsing” a very useful feature of all web browsers have been used very commonly and frequently by internet lovers, such as Internet Explorer, Mozilla Firefox, Google Chrome and Opera.“Private browsing” facilitates users to surf on Internet without leaving any traces in the computer. The browser that uses private browsing doesn’t leave the history of the websites you visit, files you download, forms you fill, your searches, etc.The best thing about “Private browsing” is very much useful for public computer.Private browsing feature is similar to the name of the “Incognito mode” in Google Chrome, “InPrivate” in Internet Explorer, etc.Official Definitions ... Read More

Generate Random Numbers Within a Given Range and Store in a List in Java

AmitDiwan
Updated on 07-Jul-2020 09:15:25

414 Views

To generate random numbers in a given range, the Java code is as follows −Example Live Demoimport java.util.Random; import java.util.*; public class Demo{    public static void main(String args[]){       Random my_rand = new Random();       List my_list_1 = new ArrayList();       int v_1 = my_rand.nextInt(1000);       int v_2 = my_rand.nextInt(967);       int v_3 = my_rand.nextInt(1050);       int v_4 = my_rand.nextInt(10000);       int v_5 = my_rand.nextInt(100);       my_list_1.add(v_1);       my_list_1.add(v_2);       my_list_1.add(v_3);       my_list_1.add(v_4);       my_list_1.add(v_5);   ... Read More

Add Button to PreferenceScreen in Android

Azhar
Updated on 07-Jul-2020 09:14:41

2K+ Views

This example demonstrates how do I add a button to PreferenceScreen in android.Step 1 − Create a new project in Android Studio, go to File rArr; New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.os.Bundle; import android.widget.Toast; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.main_activity);       getSupportFragmentManager().beginTransaction().replace(R.id.settings, new SettingsFragment()).commit();       ... Read More

Grouped Flattening of List in Python

Hafeezul Kareem
Updated on 07-Jul-2020 09:04:25

185 Views

In this tutorial, we are going to write a program that flattens a list that contains sub-lists. Given number flatten the sublists until the given number index as parts. Let's see an example to understand it clearly.Inputlists = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] number = 2Output[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]Let's see the steps to solve the problem.Initialize the list and number.Initialize an empty list.Iterate over the list with range(0, len(lists), number.Get the sublists using slicing lists[i:number].Iterate over the sublists and append the resultant list to the result list.Print the result.Example# ... Read More

Get the Old Classic Chat Interface Back in Facebook

Samual Sam
Updated on 07-Jul-2020 09:04:01

234 Views

Current Facebook page has introduced new chat sidebar and video chat feature. This chat sidebar is placed at the right-side of the Facebook pages. Friends with whom you chat always displays at the chat sidebar, by default.Facebook has also introduced the sidebar ticker for a small period of time. You can also disable Facebook sidebar Ticker. Like this; Facebook always come up with new and changed features, but it does not mean Facebook lover will like those new and changed features. That’s why, we still have an option to revert back to the old Facebook design and this article will ... Read More

Group By Matching Second Tuple Value in List of Tuples in Python

Hafeezul Kareem
Updated on 07-Jul-2020 09:03:26

487 Views

In this tutorial, we are going to write a program that groups all the tuples from a list that have same element as a second element. Let's see an example to understand it clearly.Input[('Python', 'tutorialspoints'), ('Management', 'other'), ('Django', 'tutorialspoints'), ('React', 'tutorialspoints'), ('Social', 'other'), ('Business', 'other')]Output{'tutorialspoint': [('Python', 'tutorialspoints'), ('Django', 'tutorialspoints'), ('React', 'tutorialspoints')], 'other’: [('Management', 'other'), ('Social', 'other'), ('Business', 'other')]}We have to group the tuples from the list. Let's see the steps to solve the problem.Initiate a list with required tuples.Create an empty dictionary.Iterate through the list of tuples.Check if the second element of the tuple is already present in the dictionary ... Read More

Advertisements