- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34484 Articles for Programming
![radhakrishna](https://www.tutorialspoint.com/assets/profiles/13544/profile/60_40618-1512640354.jpg)
462 Views
Following program shows how to initialize an array declared earlier.Examplepublic class Tester { int a[]; public static void main(String[] args) { Tester tester = new Tester(); tester.initialize(); } private void initialize() { a = new int[3]; a[0] = 0; a[1] = 1; a[2] = 2; for(int i=0; i< a.length ; i++) { System.out.print(a[i] +" "); } } }Output0 1 2
![mkotla](https://www.tutorialspoint.com/assets/profiles/13540/profile/60_41073-1512640012.jpg)
2K+ Views
You ByteArrayOutputStream to write byte arrays and get the result using its toByteArray() method.import java.io.ByteArrayOutputStream; import java.io.IOException; public class Tester { public static void main(String[] args) throws IOException { byte[] a = { 1,2,3}; byte[] b = { 4,5,6}; ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(a); baos.write(b); byte[] c = baos.toByteArray(); for(int i=0; i< c.length ; i++){ System.out.print(c[i] +" "); } } }Output1 2 3 4 5 6
![Giri Raju](https://www.tutorialspoint.com/assets/profiles/13536/profile/60_72105-1512540773.jpg)
2K+ Views
If you wish to create a dynamic 2d array in Java without using List. And only create a dynamic 2d array in Java with normal array then click the below linkYou can achieve the same using List. See the below program. You can have any number of rows or columns.Exampleimport java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { List rows = new ArrayList(); rows.add(new int[]{1, 2, 3}); rows.add(new int[]{1, 2}); rows.add(new int[]{1}); //get element at row : 0, column ... Read More
![Sreemaha](https://www.tutorialspoint.com/assets/profiles/13570/profile/60_64977-1512709068.jpg)
863 Views
Following example shows how to remove an element from array. Exampleimport java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList objArray = new ArrayList(); objArray.clear(); objArray.add(0,"0th element"); objArray.add(1,"1st element"); objArray.add(2,"2nd element"); System.out.println("Array before removing an element"+objArray); objArray.remove(1); objArray.remove("0th element"); System.out.println("Array after removing an element"+objArray); } }OutputThe above code sample will produce the following result. Array before removing an element[0th element, 1st element, 2nd element] Array after removing an element[2nd element]
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
206 Views
Most commonly used str() function from Python library returns a string representation of object.>>> no=100 >>> str(no) '100' >>> L1=[1,2,3,4] >>> str(L1) '[1, 2, 3, 4]' >>> d={'a': 1, 'b': 2, 'c': 3, 'd': 4} >>> str(d) "{'a': 1, 'b': 2, 'c': 3, 'd': 4}"However, repr() returns a default and unambiguous representation of the object, where as str() gives an informal representation that may be readable but may not be always unambiguous.>>> str(d) "{'a': 1, 'b': 2, 'c': 3, 'd': 4}" >>> repr(d) "{'a': 1, 'b': 2, 'c': 3, 'd': 4}" >>> repr(L1) '[1, 2, 3, 4]' >>> repr(no) '100'
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
129 Views
Complex number is made up of real and imaginary parts. Real part is a float number, and imaginary part is any float number multiplied by square root of -1 which is defined as j.>>> no=5+6j >>> no.real 5.0 >>> no.imag 6.0 >>> type(no) The resulting object is of complex data type. Python library also has complex() function, which forms object from two float arguments>>> no=complex(5,6) >>> no (5+6j) >>> no.real 5.0 >>> no.imag 6.0 >>> type(no)
![Gireesha Devara](https://www.tutorialspoint.com/assets/profiles/397483/profile/60_1063327-1637125522.jpg)
822 Views
By using the eval() function in python we can evaluate a string and return a python object. The eval() is a python built−In function that evaluates a string argument by parsing the string as a code expression. Syntax eval(expression[, globals[, locals]]) Parameters expression: It’s a string that will be evaluated as a Python expression. globals: An optional parameter, which is a dictionary containing global parameters. locals: An optional parameter, which is a dictionary containing local parameters. Return: Returns the result evaluated from the expression. If the string containing arithmetic expression If we pass a string ... Read More
![Gireesha Devara](https://www.tutorialspoint.com/assets/profiles/397483/profile/60_1063327-1637125522.jpg)
3K+ Views
We can convert a python string into tuple by simply mentioning a comma (, ) after the string. This will treat the string as a single element to the tuple. Here our string variable “s” is treated as one item in the tuple, which can be done by adding the comma after the string. Example s = "python" print("Input string :", s) t = s, print('Output tuple:', t) print(type(t)) Output Following is the output of the above program Input string : python Output tuple: ('python', ) Using tuple() function Also we can use the tuple() function ... Read More
![Gireesha Devara](https://www.tutorialspoint.com/assets/profiles/397483/profile/60_1063327-1637125522.jpg)
7K+ Views
The double star/asterisk (*) operator has more than one meaning in Python. We can use it as a exponential operator, used as function *kwargs, unpacking the iterables, and used to Merge the Dictionaries. Exponential operator For numeric data the double asterisk (**) is used as an exponential operator. Let's take an example and see how the double star operator works on numeric operands. Example The following example uses double asterisks/star (**) to calculate “a to the power b” and it works equivalent to the pow() function. a = 10 b = 2 result = a ** b print("a**b = ", ... Read More
![Vikram Chiluka](https://www.tutorialspoint.com/assets/profiles/495654/profile/60_4081994-1659334126.jpg)
5K+ Views
In Python, a list is an ordered sequence that can hold several object types such as integer, character, or float. In other programming languages, a list is equivalent to an array. In this article, we will show you how to get the size/length of a list in different ways using Python. Here we see 4 methods − Using len() function Using For Loop (Naïve Method) Using length_hint() function Using __len__() function Assume we have taken a list containing some elements. We will return the length/size of the given input list using different methods as specified above. Method 1: ... Read More