Java Array String

362 views 11 slides May 16, 2021
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

This presentation contain details of array and string


Slide Content

Array In Java Created by Manish Tiwari

Presentation By Manish Tiwari , Assistant Professor, Software Engineer, Computer Science and Application

2. WhatsApp : ? 4. Blog : manishtiwarise.blogspot.in 3. Email : [email protected] 1. Twitter : @ manishtiwarise 5. SlideShare : https ://www.slideshare.net/tiwarikmanish Find Notes

A R R A Y S 1 2 3 4 5 Element Index

Array is a collection of similar type(Homogeneous) of elements stored in contiguous memory location. Definition of Java Array Code Optimization:  It makes the code optimized, we can retrieve or sort the data easily. Random access:  We can get any data located at any index position. Advantage of Java Array 1. Size Limit:  We can store only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in java. Disadvantage of Java Array

Single Dimensional Array Syntax: // preferred way. DataType [] ArrayName ; Example: double[] myList ; 2. DataType ArrayName []; Example: double myList []; Types of Java Array 2. Multidimensional Array Syntax: // preferred way. 1. dataType [][]  arrayRefVar ; (or)   2. dataType  [][] arrayRefVar ; (or)   3. dataType   arrayRefVar [][]; (or)   4. dataType  [] arrayRefVar [];   0 There are Two Types of Array.

class   Testarray {   public   static   void  main(String  args []) {      int  a[]= new   int [5];//declaration and instantiation   a[0]=10;//initialization   a[1]=20;   a[2]=70;   a[3]=40;   a[4]=50;      //printing array   for ( int   i =0;i< a.length;i ++)//length is the property of array   System.out.println (a[ i ]);      } }   Program-Single Dimensional Array

class  Testarray1 {   public   static   void  main(String  args []) {      int  a[]={33,3,4,5}; //declaration, instantiation and initialization      //printing array   for ( int   i =0;i< a.length;i ++) //length is the property of array   System.out.println (a[ i ]);   } } Declaration, Instantiation and Initialization of Java Array

class  Testarray5 {   public   static   void  main(String  args []){   int  a[][]={{1,3,4},{3,4,5}};   int  b[][]={{1,3,4},{3,4,5}};      int  c[][]= new   int [2][3];      for ( int   i =0;i<2;i++) {   for ( int  j=0;j<3;j++) {   c[ i ][j]=a[ i ][j]+b[ i ][j];   System.out.print (c[ i ][j]+" ");   }   System.out.println ();//new line   }     } }    Adding 2 Matrices Using Multi Dimensional

S tring is a sequence of characters. But in java, string is an object that represents a sequence of characters. The java.lang.String class is used to create string object. String in Java String Types There are two ways to create String object: By string literal String s="welcome";   2. By new keyword String s= new  String("Welcome");

String Program public   class   StringExample {   public static void main(String  args []) {   String s1="java"; char   ch []={' s','t','r','i','n','g','s '};   String s2= new  String( ch ); String s3= new  String("example"); System.out.println (s1);   System.out.println (s2);   System.out.println (s3);   System.out.println (s1.toUpperCase()); System.out.println (s1.toLowerCase()); System.out.println (s2.charAt(3)); System.out.println (s2.length()); System.out.println (s3.trim());   System.out.println (s3.startsWith(“s"));//true     System.out.println (s1.endsWith(“s"));//true   } }