Found 34489 Articles for Programming

Are there any ways to Manipulate Strings in Java.

Naveen Singh
Updated on 26-Feb-2020 05:11:31

101 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.

Naveen Singh
Updated on 26-Feb-2020 05:09:40

3K+ 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?

Naveen Singh
Updated on 30-Jul-2019 22:30:21

131 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?

Naveen Singh
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

Naveen Singh
Updated on 26-Feb-2020 05:46:34

16K+ 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?

Naveen Singh
Updated on 25-Feb-2020 11:24:09

282 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?

Naveen Singh
Updated on 15-May-2023 13:26:57

302 Views

The update method is one of the methods of 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. The dictionary is represented by curly braces{}.The dictionary contains key and value pairs, combinedly called as 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 colon and the key ... Read More

How do we use double quotation in Python?

Naveen Singh
Updated on 15-May-2023 13:24:16

468 Views

Double quotes are used to represent a string or a character as well as can be used in the print function to print the defined statement as the output. The functionality of the single quotes and double quotes is same. We can use any type quotes as per our requirement. The following is the syntax to create a string using the double quotes in the python programming language. str = “text” Where, “ ” are the double quotations text is the data to be in string format Example Let’s see an example to understand the functionality and ... Read More

How I can dump a Python tuple in JSON format?

Naveen Singh
Updated on 15-May-2023 12:46:09

808 Views

JSON can be abbreviated as JavaScript Object Notation. It means a script of a text file in a programming language to transfer and store the data. It is supported by the python programming language using a built-in package named json. It’s text is given in the quoted string format which contains a key and value within the curly braces{} which looks like a dictionary. To access a JSON document using python we have to import the json package. In this package we have a method named dumps() which is used to convert the python tuple objects into the Java ... Read More

List vs tuple vs dictionary in Python

Naveen Singh
Updated on 15-May-2023 11:12:02

24K+ Views

In python there are different types of data structures. Among them list, tuple, dictionary. All these three are used to store the data in the python programming language. What is a List? List is one of the data structures available in python which is used to store multiple values in a single data structure. We can create a list in Python using the square braces[ ]. It is mutable which means that we can modify a list once it is created. It takes multiple elements of different data types such as int, float, str etc which are separated by ... Read More

Advertisements