Found 33676 Articles for Programming

Are there any ways to Manipulate Strings in Java.

Ayyan
Updated on 26-Feb-2020 05:11:31

170 Views

Since String class is immutable once created we cannot modify the data of the string. But still, if you want to manipulate string data you can rely on StringBuffer or StringBuilder classes.Examplepublic class Test {    public static void main(String args[]) {       String str = "Hi welcome ";       StringBuffer sb= new StringBuffer(str);       sb.append("to Tutorialspoint");       System.out.println(sb);    } }OutputHi welcome to Tutorialspoint

Java Program to reverse a given String with preserving the position of space.

Akshaya Akki
Updated on 26-Feb-2020 05:09:40

5K+ Views

You can reverse the contents of a given String using leaving the spaces using the reverse() method of the StringBuffer class.Examplepublic class Test {    public static void main(String args[]) {       String str = "hi welcome to Tutorialspoint";       String strArray[] = str.split(" ");       StringBuffer sb= new StringBuffer(str);       sb.reverse();       for(int i=0 ; i

Learn Everything about Java String?

George John
Updated on 30-Jul-2019 22:30:21

293 Views

The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant, their values cannot be changed after they are created. To learn more about Strings visit Tutorialspoint Strings page.

How to remove the last character from a string in Java?

Alankritha Ammu
Updated on 26-Feb-2020 05:07:49

2K+ Views

The StringBuffer class contains a method known as deleteCharAt(). This method deletes the character at a specified index/position. You can use this method to delete/remove a particular character from a string in Java.Examplepublic class Test {    public static void main(String args[]){       String str = "hi welcome to Tutorialspoint";       StringBuffer sb= new StringBuffer(str);       sb.deleteCharAt(sb.length()-1);       System.out.println(sb);    } }Outputhi welcome to Tutorialspoint

String Handling in Java

Arushi
Updated on 26-Feb-2020 05:46:34

17K+ Views

Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects.The Java platform provides the String class to create and manipulate strings.The most direct way to create a string is to write −String greeting = "Hello world!";Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'.ExampleLive Demopublic class StringDemo {    public static void main(String args[]) {       char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.' };       String helloString ... Read More

How does Python dictionary keys() Method work?

Jayashree
Updated on 25-Feb-2020 11:24:09

387 Views

The keys() method of Python dictionary class returns a view object consisting of keys used in the dictionary.>>> d1 = {'name': 'Ravi', 'age': 21, 'marks': 60, 'course': 'Computer Engg'} >>>d1.keys() dict_keys(['name', 'age', 'marks', 'course'])It can be stored as a list object. If new key-value pair is added, the view object is automatically updated.>>> l1=d1.keys() >>> l1 dict_keys(['name', 'age', 'marks', 'course']) >>>d1.update({"college":"IITB"}) >>> l1 dict_keys(['name', 'age', 'marks', 'course', 'college'])

What is usage of update method in Python dictionary?

Niharika Aitam
Updated on 24-Apr-2025 19:03:31

507 Views

The update method is one of the methods of the dictionary data structure. It is used to update the values in the already created dictionary, which means it adds a new key-value pair to the dictionary. The updated key and value will be updated at the last. Python update() Method in Dictionary The dictionary is represented by curly braces{}. The dictionary contains key and value pairs, collectively called items, which can accept any data type of elements as values. It is mutable, which means once the dictionary is created, we can apply the changes. It has key-value pairs separated by ... Read More

How to declare a multi dimensional dictionary in Python?

Niharika Aitam
Updated on 17-Apr-2025 16:45:32

1K+ Views

Multidimensional Dictionaries in python Multidimensional dictionaries are part of the dictionaries in Python, which are used to store data. Created by assigning a dictionary to a key within another dictionary, these structures are represented by curly braces {} and can accommodate any data type. Their mutable nature allows modifications after creation. They are composed of unique key-value pairs, separated by a colon (:). While keys are unique, values can be duplicated. Accessing values requires using keys, as dictionaries do not support indexing. To retrieve specific key values, use the key combined with indexing. Syntax The following is the syntax for ... Read More

How to serialize Python dictionary to XML?

Niharika Aitam
Updated on 28-Feb-2025 19:25:35

216 Views

The XML is the markup language used to transfer the data. The XML syntax is the same as the HTML, whereas the tags are predefined in HTML and not in XML. This offers us to store the data between the opening and closing tags. In Python, dictionaries store data as key-value pairs. We can serialize a dictionary to XML format using two popular libraries: dict2xml (widely used) dicttoxml ... Read More

How do we use double quotation in Python?

Niharika Aitam
Updated on 29-May-2025 11:27:14

636 Views

Double Quotes in PythonDouble quotes are used to represent a string or a character. The functionality of the single quotes and double quotes is the same. We can use any type of quote as per our requirement. The following is the syntax to create a string using double quotes in the Python programming language. str = “text” Example Let’s see an example to understand the functionality and usage of the double quotes in Python. Initially, we have created a string by passing the sentence in double quotes and assigned it to the variable str. Next we printed ... Read More

Advertisements