Programming Articles

Page 5 of 2544

Split String with Comma (,) in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 34K+ Views

Let’s say the following is our string.String str = " This is demo text, and demo line!";To split a string with comma, use the split() method in Java.str.split("[,]", 0);The following is the complete example.Examplepublic class Demo {     public static void main(String[] args) {        String str = "This is demo text, and demo line!";        String[] res = str.split("[,]", 0);        for(String myStr: res) {           System.out.println(myStr);        }     } }OutputThis is demo text and demo line!

Read More

How to check if a C/C++ string is an int?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 31K+ Views

There are several methods to check that string is an int or not and one of those method is to use isdigit() to check the string.Here is an example to check whether a string is an int or not in C++ language,Example#include #include using namespace std; int main() {    char str[] = "3257fg";    for (int i = 0; i < strlen(str); i++) {       if(isdigit(str[i]))       cout

Read More

How to find the first character of a string in C#?

George John
George John
Updated on 11-Mar-2026 45K+ Views

To get the first character, use the substring() method.Let’s say the following is our string −string str = "Welcome to the Planet!";Now to get the first character, set the value 1 in the substring() method.string res = str.Substring(0, 1);Let us see the complete code −Exampleusing System; public class Demo {    public static void Main() {       string str = "Welcome to the Planet!";       string res = str.Substring(0, 1);       Console.WriteLine(res);    } }OutputW

Read More

How to find the index of an item in a C# list in a single step?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 41K+ Views

To get the index of an item in a single line, use the FindIndex() and Contains() methods.int index = myList.FindIndex(a => a.Contains("Tennis"));Above, we got the index of an element using the FindIndex(), which is assisted by Contains() method for that specific element.Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Program {    public static void Main() {       List myList = new List () {          "Football",          "Soccer",          "Tennis",       };       // finding index       int index = myList.FindIndex(a => a.Contains("Tennis"));       // displaying index       Console.WriteLine("List Item Tennis Found at index: " + index);    } }OutputList Item Tennis Found at index: 2

Read More

Add key-value pair in C# Dictionary

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 29K+ Views

To add key-value pair in C# Dictionary, firstly declare a Dictionary.IDictionary d = new Dictionary();Now, add elements with KeyValuePair.d.Add(new KeyValuePair(1, "TVs")); d.Add(new KeyValuePair(2, "Appliances")); d.Add(new KeyValuePair(3, "Mobile"));After adding elements, let us display the key-value pair.Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       IDictionary d = new Dictionary();       d.Add(new KeyValuePair(1, "TVs"));       d.Add(new KeyValuePair(2, "Appliances"));       d.Add(new KeyValuePair(3, "Mobile"));       d.Add(new KeyValuePair(4, "Tablet"));       d.Add(new KeyValuePair(5, "Laptop"));       d.Add(new KeyValuePair(6, "Desktop"));       d.Add(new KeyValuePair(7, "Hard Drive"));   ...

Read More

C# Program to check if a number is prime or not

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 66K+ Views

To calculate whether a number is prime or not, we have used a for loop. Within that on every iteration, we use an if statement to find that the remainder is equal to 0, between the number itself.for (int i = 1; i

Read More

How to pop the first element from a C# List?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 34K+ Views

To pop the first element in the list, use the RemoveAt() method. It eliminates the element from the position you want to remove the element.Set the listList myList = new List() {    "Operating System",    "Computer Networks",    "Compiler Design" };Now pop the first element using RemoveAt(0)myList.RemoveAt(0);Let us see the complete example.Exampleusing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       List myList = new List() {          "Operating System",          "Computer Networks",          "Compiler Design"       };   ...

Read More

Array Copy in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 30K+ Views

Array in Java can be copied to another array using the following ways.Using variable assignment. This method has side effects as changes to the element of an array reflects on both the places. To prevent this side effect following are the better ways to copy the array elements.Create a new array of the same length and copy each element.Use the clone method of the array. Clone methods create a new array of the same size.Use System.arraycopy() method.  The arraycopy() can be used to copy a subset of an array.ExampleCreate a java class named Tester.Tester.javapublic class Tester {    public static ...

Read More

How to read inputs as integers in C#?

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 32K+ Views

To read inputs as integers in C#, use the Convert.ToInt32() method.res = Convert.ToInt32(val);Let us see how −The Convert.ToInt32 converts the specified string representation of a number to an equivalent 32-bit signed integer.Firstly, read the console input −string val; val = Console.ReadLine();After reading, convert it to an integer.int res; res = Convert.ToInt32(val);Let us see an example −Exampleusing System; using System.Collections.Generic; class Demo {    static void Main() {       string val;       int res;           Console.WriteLine("Input from user: ");       val = Console.ReadLine();       // convert to ...

Read More

C# Program to Convert Integer to String

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 46K+ Views

To convert an integer to string in C#, use the ToString() method.Set the integer for which you want the string −int num = 299;Use the ToString() method to convert Integer to String −String s; int num = 299; s = num.ToString();ExampleYou can try to run the following code to convert an integer to string in C# −using System; class MyApplication {    static void Main(string[] args) {       String s;       int num = 299;       s = num.ToString();       Console.WriteLine("String = "+s);       Console.ReadLine();    } }OutputString = 299

Read More
Showing 41–50 of 25,433 articles
« Prev 1 3 4 5 6 7 2544 Next »
Advertisements