<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4549513797136890259</id><updated>2025-09-24T02:50:24.873+05:30</updated><category term="ArrayList"/><category term="Callable Statement"/><category term="Collections in  Java"/><category term="Comparable vs Comparator"/><category term="Constructor in Java"/><category term="Cookie in Servlet"/><category term="Custom Tags"/><category term="EJB in Java"/><category term="Encapsulation"/><category term="Exception Handling in Java"/><category term="Final keyword"/><category term="GenericServlet Class"/><category term="Get Form Data in servlet"/><category term="Go"/><category term="Go Installation"/><category term="Go Programming Language"/><category term="Golang"/><category term="HTTP Protocol"/><category term="HTTP Requests"/><category term="Hidden Form Field in Servlet"/><category term="HttpServlet Class"/><category term="HttpSession in Servlet"/><category term="Inheritance in Java"/><category term="J2EE"/><category term="JAAS"/><category term="JDBC Driver"/><category term="JSP Action Tags"/><category term="JSP Exception Handling"/><category term="JSP Implicit Objects"/><category term="JSP Life Cycle"/><category term="JSP Scripting Elements"/><category term="JSP expression language"/><category term="JSP introduction"/><category term="JSTL"/><category term="Java"/><category term="Java Access Modifiers"/><category term="Java Arithmetic Operators"/><category term="Java ArrayDeque"/><category term="Java Assignment Operators"/><category term="Java Bitwise operators"/><category term="Java Control Statements"/><category term="Java Deque"/><category term="Java Dictionary"/><category term="Java Environment Set"/><category term="Java HashMap"/><category term="Java HashSet"/><category term="Java Hashtable"/><category term="Java Hello World Program"/><category term="Java Interface"/><category term="Java Interview Questions and Answers"/><category term="Java LinkedHashSet"/><category term="Java Logical Operators"/><category term="Java NavigableSet"/><category term="Java OOPs"/><category term="Java Operators"/><category term="Java PriorityQueue"/><category term="Java Queue"/><category term="Java Relational Operators"/><category term="Java SortedMap"/><category term="Java SortedSet"/><category term="Java Stack"/><category term="Java String Class"/><category term="Java String compareTo()"/><category term="Java String lastIndexOf()"/><category term="Java String length() method"/><category term="Java String toCharArray()"/><category term="Java String toLowerCase()"/><category term="Java String toUpperCase()"/><category term="Java String trim() method"/><category term="Java Switch Statement"/><category term="Java Ternary Operator"/><category term="Java TreeSet"/><category term="Java Unary Operators"/><category term="Java Variables"/><category term="Java Vector"/><category term="Java While Loop"/><category term="Java break"/><category term="Java continue statement"/><category term="Java do-while loop"/><category term="Java equals() method"/><category term="Java for loop"/><category term="Java if statement"/><category term="Java if-else statement"/><category term="Java if-else-if ladder"/><category term="Java instanceof"/><category term="Java isEmpty() method"/><category term="Java nested-if"/><category term="Java substring() method"/><category term="JavaBeans"/><category term="LinkedHashMap"/><category term="LinkedList"/><category term="Linux"/><category term="MVC in jsp"/><category term="MacOS"/><category term="Polymorphism in Java"/><category term="PreparedStatement java"/><category term="Serialization in Java"/><category term="Servlet"/><category term="Servlet Hello World"/><category term="Servlet Life Cycle"/><category term="Servlet interface"/><category term="Session Tracking"/><category term="Statement interface"/><category term="Statement vs PreparedStatement vs CallableStatement"/><category term="Stored Procedure"/><category term="String indexOf() method"/><category term="Super keyword"/><category term="TreeMap"/><category term="Url Rewriting in Servlet"/><category term="abstract class in java"/><category term="array in java"/><category term="charAt() method"/><category term="class and object"/><category term="concat() method in java"/><category term="equalsIgnoreCase() method in java"/><category term="final vs immutable"/><category term="immutable class in java"/><category term="java data types"/><category term="java database connection"/><category term="java map"/><category term="java return statement"/><category term="jsp directives"/><category term="packages in java"/><category term="replace a string in java"/><category term="servlet API"/><category term="substring in java"/><category term="this keyword"/><category term="windows"/><title type='text'>Javastudypoint </title><subtitle type='html'>Javastudypoint provides free online tutorials on all the technologies like Java, JDBC, Servlet, JSP, Java Beans, Golang, etc., and Computer Science and Programming.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>123</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-1978115700609001493</id><published>2023-08-28T23:11:00.001+05:30</published><updated>2023-08-28T23:11:51.047+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Go Installation"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="MacOS"/><category scheme="http://www.blogger.com/atom/ns#" term="windows"/><title type='text'>How to install Go on Windows, Linux and MacOS</title><content type='html'>&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;This post will show &lt;b style=&quot;color: black;&quot;&gt;how to install Go on Windows, Linux, and MacOS&lt;/b&gt;. Before installing Go, It&#39;s essential to know what GoLang is.&amp;nbsp;Go is an open-source, compiled, high-level, and statically typed programming language. It is also known as GoLang. It was designed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It was developed to improve programming productivity in the era of multicore, networked machines, and large codebases.&amp;nbsp;Go is widely used in production at Google and in many other organizations and open-source projects. For more details about GoLang refer to this article &lt;i&gt;&lt;a href=&quot;https://www.javastudypoint.com/2023/08/what-is-go-programming-language.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;Introduction to Go Programming Language&lt;/span&gt;&lt;/a&gt;&lt;/i&gt;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Let&#39;s discuss how to install Go on Windows, Linux, and macOS&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;b&gt;How to Install Go on Windows:&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;To install Go on a Windows system, follow these steps:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;/ol&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Go to the official GoLang website&#39;s download page: &lt;a href=&quot;https://golang.org/dl/&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;https://golang.org/dl/&lt;/span&gt;&lt;/a&gt;. Download the Windows installer that matches your system architecture (either 32-bit or 64-bit).&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Once the installer is downloaded, double-click on it to run it. The installer will guide you through the installation process.&lt;/span&gt;&lt;/li&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: black;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5zBS0284aaGtklSoPadZcS2dSW2cNEFY5vq-xoYQtc0PZGBaWuE2jeq-BMB-ckBqRhPMhTPiZ4glgKA57jgx8j3JVn0PGzhtkGkR7PxEdp8PaCSHaXMgTicJs4UthgmJGTjRn-WRk3V0609G-xBtGw5mWEw_nO5Qg1IITlnbQaxoXZUBNactlAbI8dXRw/s769/image1.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;How to install Go on Windows, Linux and MacOS&quot; border=&quot;0&quot; data-original-height=&quot;599&quot; data-original-width=&quot;769&quot; height=&quot;311&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5zBS0284aaGtklSoPadZcS2dSW2cNEFY5vq-xoYQtc0PZGBaWuE2jeq-BMB-ckBqRhPMhTPiZ4glgKA57jgx8j3JVn0PGzhtkGkR7PxEdp8PaCSHaXMgTicJs4UthgmJGTjRn-WRk3V0609G-xBtGw5mWEw_nO5Qg1IITlnbQaxoXZUBNactlAbI8dXRw/w400-h311/image1.png&quot; title=&quot;How to install Go on Windows, Linux and MacOS&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;li style=&quot;color: black;&quot;&gt;Click on the next and&amp;nbsp;You will be asked to choose the installation location. The default location is fine but you can choose according to your preference.&amp;nbsp;&lt;/li&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: black;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiouxFYZnA4fcb97zKKfNpYZyAT0xz0G6jZ-4nPLQ1KWcI-nxwo8H8WC3ZnrVACvvr77CKcEzaJB8kn8rpIWoI8Tv4rYiIMzac9VGcY6_s79Lte0Z_ollZKnoaLyfzWWFJk2QB210bwXaF1VHjzX-QSMBUQb9PQoCM6MlsmQBVABclXtwyBnyGZTCq04dRW/s765/image2.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;How to install Go on Windows, Linux and MacOS&quot; border=&quot;0&quot; data-original-height=&quot;598&quot; data-original-width=&quot;765&quot; height=&quot;313&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiouxFYZnA4fcb97zKKfNpYZyAT0xz0G6jZ-4nPLQ1KWcI-nxwo8H8WC3ZnrVACvvr77CKcEzaJB8kn8rpIWoI8Tv4rYiIMzac9VGcY6_s79Lte0Z_ollZKnoaLyfzWWFJk2QB210bwXaF1VHjzX-QSMBUQb9PQoCM6MlsmQBVABclXtwyBnyGZTCq04dRW/w400-h313/image2.png&quot; title=&quot;How to install Go on Windows, Linux and MacOS&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;li style=&quot;color: black;&quot;&gt;After making your selections, click on next and then click the &quot;Install&quot; button to start the installation.&lt;/li&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: black;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQDdwvoJLIODNBStFFZOpL2n6c731v8eDcw7mek6PWFXCkRPDb9j5qrqgp3MtzaX6XOhGwYkT7bDYYhdwp8tpeRtLtmjS_6pS2feeZVLVU1w-nTE0ACAPYHCMHx76FUNToCw2rCmJQLHrYyuuno9x5DaEojxukEHbn3Hwnd0zmKPpgIGLfH11TPBxBdmjx/s764/image3.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;How to install Go on Windows, Linux and MacOS&quot; border=&quot;0&quot; data-original-height=&quot;592&quot; data-original-width=&quot;764&quot; height=&quot;310&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQDdwvoJLIODNBStFFZOpL2n6c731v8eDcw7mek6PWFXCkRPDb9j5qrqgp3MtzaX6XOhGwYkT7bDYYhdwp8tpeRtLtmjS_6pS2feeZVLVU1w-nTE0ACAPYHCMHx76FUNToCw2rCmJQLHrYyuuno9x5DaEojxukEHbn3Hwnd0zmKPpgIGLfH11TPBxBdmjx/w400-h310/image3.png&quot; title=&quot;How to install Go on Windows, Linux and MacOS&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;li style=&quot;color: black;&quot;&gt;Once the installation is complete, you can verify whether Go has been installed successfully or not. Open a command prompt (CMD) or PowerShell window and type: &lt;i&gt;&quot;go version&quot;. &lt;/i&gt;If the Go is installed successfully, You will get a displayed Go version on the CMD screen.&lt;/li&gt;&lt;/ol&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrODQyQrho0xkDYFsTHFSMpaFfyLchOCNbrt5XSzRqqhsuY0FjQM7eHBve4iK5jTXnediY-lPrjrVccehRYpcfk6PDwkwB4eSF_aEOP89IspFj3UkYryDNvPrwA_F9awS_dLheN_q05cFRbW6aWGqUTZUX6raYrprcFCZlJfBzHZJmM8a0U9MF6D2rt0D0/s692/Capture.PNG&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;How to install Go on Windows, Linux and MacOS&quot; border=&quot;0&quot; data-original-height=&quot;348&quot; data-original-width=&quot;692&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrODQyQrho0xkDYFsTHFSMpaFfyLchOCNbrt5XSzRqqhsuY0FjQM7eHBve4iK5jTXnediY-lPrjrVccehRYpcfk6PDwkwB4eSF_aEOP89IspFj3UkYryDNvPrwA_F9awS_dLheN_q05cFRbW6aWGqUTZUX6raYrprcFCZlJfBzHZJmM8a0U9MF6D2rt0D0/w400-h201/Capture.PNG&quot; title=&quot;How to install Go on Windows, Linux and MacOS&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;How to install&amp;nbsp;Go on Linux&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;To install Go on a Linux system, follow these steps:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;span&gt;&lt;li&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Go to the official GoLang website&#39;s download page:&amp;nbsp;&lt;a href=&quot;https://golang.org/dl/&quot; style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;https://golang.org/dl/&lt;/span&gt;&lt;/a&gt;. Download the tar file.&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Once the tar file is downloaded, remove any previous Go installation by deleting the &lt;i&gt;/usr/local/go&lt;/i&gt; folder (if it exists), then extract the archive you just downloaded into &lt;i&gt;/usr/local&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
$ rm -rf /usr/local/go &amp;amp;&amp;amp; tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;
&lt;li style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Add /usr/local/go/bin to the PATH environment variable. You can do this by adding the following line to your $HOME/.profile or /etc/profile&lt;/span&gt;&lt;/li&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
export PATH=$PATH:/usr/local/go/bin
&lt;/code&gt;&lt;/pre&gt;
&lt;li style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Save the profile file and then run &lt;b&gt;source .profile&lt;/b&gt; to apply the changes in the system.&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;Now you can check whether Go is installed successfully by using the&amp;nbsp;&lt;i&gt;&quot;go version&quot;&lt;/i&gt; command.&amp;nbsp;If the Go is installed successfully, You will get a displayed Go version&lt;/span&gt;&lt;/li&gt;&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
source .profile

go version
go version go1.21.0 windows/amd64
&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;
  
How to install Go on MacOs
&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span style=&quot;color: black; font-family: verdana;&quot;&gt;To install Go on a Mac system, follow these steps:&lt;div&gt;&lt;ol style=&quot;color: black; text-align: left;&quot;&gt;&lt;li&gt;Go to the official Golang website download page&amp;nbsp;&lt;a href=&quot;https://golang.org/dl/&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span&gt;&lt;/span&gt;https://golang.org/dl/&lt;/span&gt;&lt;/a&gt;. You will see different options for Golang download for different operating systems. Look at the Mac System version and download it.&lt;/li&gt;&lt;li style=&quot;color: black;&quot;&gt;Once it is downloaded start the installation process. Follow the on-screen instructions in the installer.&lt;/li&gt;&lt;li style=&quot;color: black;&quot;&gt;Once the installation is complete, you can check the Go installation using go version command&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
go version
go version go1.21.0 windows/amd64
&lt;/code&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/1978115700609001493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2023/08/how-to-install-go-on-windows-linux-macos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1978115700609001493'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1978115700609001493'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2023/08/how-to-install-go-on-windows-linux-macos.html' title='How to install Go on Windows, Linux and MacOS'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5zBS0284aaGtklSoPadZcS2dSW2cNEFY5vq-xoYQtc0PZGBaWuE2jeq-BMB-ckBqRhPMhTPiZ4glgKA57jgx8j3JVn0PGzhtkGkR7PxEdp8PaCSHaXMgTicJs4UthgmJGTjRn-WRk3V0609G-xBtGw5mWEw_nO5Qg1IITlnbQaxoXZUBNactlAbI8dXRw/s72-w400-h311-c/image1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-1543172019424679192</id><published>2023-08-12T21:15:00.000+05:30</published><updated>2023-08-12T21:15:14.342+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Go"/><category scheme="http://www.blogger.com/atom/ns#" term="Go Programming Language"/><category scheme="http://www.blogger.com/atom/ns#" term="Golang"/><title type='text'>What is GoLang? Introduction to Go Programming Language</title><content type='html'>&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Go&lt;/b&gt; is an open-source, compiled, high-level, and statically typed programming language. It is also known as &lt;b&gt;GoLang&lt;/b&gt;. It was designed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is developed to improve programming productivity in the era of multicore, networked machines, and large codebases. Go was publicly launched in 2009 and version 1.0 was released in March 2012. Go is widely used in production at Google and in many other organizations and open-source projects.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Why should you learn GoLang?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Go&lt;/b&gt; language is one of the fastest-growing, in-demand skills and rising programming languages and it makes sense to learn Go language to develop Software in a quicker time. Let&#39;s discuss some use cases to learn to Go Programming Language.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Cloud and Network Services:&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h4&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;GoLang&lt;/b&gt; helps enterprises build and scale cloud computing systems. Most of the cloud-native software is written in GoLang. The major cloud providers like &lt;a href=&quot;https://en.wikipedia.org/wiki/Google_Cloud_Platform&quot; target=&quot;_blank&quot;&gt;GCP&lt;/a&gt; (Google Cloud Platform), &lt;a href=&quot;https://en.wikipedia.org/wiki/Amazon_Web_Services&quot; target=&quot;_blank&quot;&gt;AWS&lt;/a&gt; (Amazon Web Services), and Azure have Go APIs for services, and popular open-source libraries provide support for API tooling (&lt;a href=&quot;https://github.com/go-swagger/go-swagger&quot; target=&quot;_blank&quot;&gt;Swagger&lt;/a&gt;), transport (&lt;a href=&quot;https://github.com/golang/protobuf&quot; target=&quot;_blank&quot;&gt;protocol buffers&lt;/a&gt;, &lt;a href=&quot;https://grpc.io/docs/quickstart/go/&quot; target=&quot;_blank&quot;&gt;gRPC&lt;/a&gt;), monitoring (&lt;a href=&quot;https://godoc.org/go.opencensus.io&quot; target=&quot;_blank&quot;&gt;OpenCensus&lt;/a&gt;), Object-Relational Mapping (&lt;a href=&quot;https://gorm.io/&quot; target=&quot;_blank&quot;&gt;gORM&lt;/a&gt;), and authentication (&lt;a href=&quot;https://github.com/dgrijalva/jwt-go&quot; target=&quot;_blank&quot;&gt;JWT&lt;/a&gt;). The open-source community also provided several frameworks including &lt;a href=&quot;https://gokit.io/&quot; target=&quot;_blank&quot;&gt;Go Kit&lt;/a&gt;, &lt;a href=&quot;https://micro.mu/docs/go-micro.html&quot; target=&quot;_blank&quot;&gt;Go Micro&lt;/a&gt;, and &lt;a href=&quot;https://github.com/nytimes/gizmo&quot; target=&quot;_blank&quot;&gt;Gizmo&lt;/a&gt; which can help the developer to build the cloud-based application easily and in a quicker time.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;There are two widely used Go tools for cloud computing &lt;a href=&quot;https://www.docker.com/&quot; target=&quot;_blank&quot;&gt;Docker&lt;/a&gt; and &lt;a href=&quot;https://kubernetes.io/&quot; target=&quot;_blank&quot;&gt;Kubernetes&lt;/a&gt;. Clod Developers use docker to quickly deploy and scale applications into any environment and developers use Kubernetes to build, deliver, and scale containerized apps quickly.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;h4 style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;b&gt;CLI (Command Line Interfaces):&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Command-line_interface&quot; target=&quot;_blank&quot;&gt;CLI&lt;/a&gt; developers prefer Golang portability, performance, and ease of creation.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Developers of CLIs find Go to be ideal for designing their applications. Go compiles very quickly into a single binary, works across platforms with a consistent style, and brings a strong development community. From a single Windows or Mac laptop, developers can build a Go program for every one of the dozens of architectures and operating systems Go supports in a matter of seconds, no complicated build farms are needed. No other compiled language can be built as portably or quickly. Go applications are built into a single self-contained binary making installing Go applications trivial.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;When developing CLIs in &lt;b&gt;Golang&lt;/b&gt;, two tools are widely used: Cobra &amp;amp; Viper&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;a href=&quot;https://pkg.go.dev/github.com/spf13/cobra&quot; target=&quot;_blank&quot;&gt;Cobra&lt;/a&gt; &lt;span style=&quot;color: black;&quot;&gt;is a Golang library for creating powerful modern CLI interfaces.&amp;nbsp;In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;a href=&quot;https://pkg.go.dev/github.com/spf13/viper?tab=overview&quot; target=&quot;_blank&quot;&gt;Viper&lt;/a&gt; &lt;span style=&quot;color: black;&quot;&gt;is a complete configuration solution for Go applications, designed to work within an app to handle configuration needs and formats.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Cobra and Viper are designed to work together.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Viper supports nested structures in the configuration, allowing CLI developers to manage the configuration for multiple parts of a large application.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Viper also provides all of the tooling needed to easily build &lt;a href=&quot;https://en.wikipedia.org/wiki/Twelve-Factor_App_methodology&quot; target=&quot;_blank&quot;&gt;twelve-factor apps&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;GoLang for Web Development:&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Go&lt;/b&gt; &lt;span style=&quot;color: black;&quot;&gt;can be an excellent choice for web development, particularly for applications that prioritize performance, scalability, and concurrent handling of requests.&amp;nbsp;Go is designed to enable developers to rapidly develop scalable and secure web applications.&amp;nbsp;&lt;b&gt;Go &lt;/b&gt;have standard libraries that include packages for building web servers, handling HTTP requests, and working with templates.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;This reduces the need for third-party libraries and simplifies the development process.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Go&lt;/b&gt; &lt;span style=&quot;color: black;&quot;&gt;has excellent support for all of the latest technologies from &lt;a href=&quot;https://pkg.go.dev/net/http&quot; target=&quot;_blank&quot;&gt;HTTP/2&lt;/a&gt;, to databases like &lt;a href=&quot;https://pkg.go.dev/mod/github.com/go-sql-driver/mysql&quot; target=&quot;_blank&quot;&gt;MySQL&lt;/a&gt;, &lt;a href=&quot;https://pkg.go.dev/mod/go.mongodb.org/mongo-driver&quot; target=&quot;_blank&quot;&gt;MongoDB&lt;/a&gt;, and &lt;a href=&quot;https://pkg.go.dev/mod/github.com/elastic/go-elasticsearch/v8&quot; target=&quot;_blank&quot;&gt;Elasticsearch&lt;/a&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;to the latest encryption standards including &lt;a href=&quot;https://pkg.go.dev/crypto/tls&quot; target=&quot;_blank&quot;&gt;TLS 1.3&lt;/a&gt; that help to develop secure and user-friendly web applications.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;b&gt;Development Operations &amp;amp; Site Reliability Engineering:&lt;/b&gt;&lt;/span&gt;&lt;/h4&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Go&lt;/b&gt; &lt;span style=&quot;color: black;&quot;&gt;offers several features and benefits that can greatly assist Development Operations (DevOps) and Site Reliability Engineering (SRE) teams in their day-to-day tasks and responsibilities. Go compiles very quickly into a single binary, Go&#39;s single-binary output means that DevOps and SRE teams can package their tools and services as standalone executables, reducing dependencies and easing deployment across various environments.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Go&lt;/b&gt; &lt;span style=&quot;color: black;&quot;&gt;can be used to create custom automation scripts and tools that streamline &lt;a href=&quot;https://www.redhat.com/en/topics/devops/what-cicd-pipeline&quot; target=&quot;_blank&quot;&gt;CI/CD pipelines&lt;/a&gt;, automate testing, deployment, and monitoring, and enhance overall workflow efficiency.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;How GoLang is different from other programming languages&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;The most notable difference between &lt;b&gt;GoLang&lt;/b&gt; and many other programming languages is its concurrency model. Traditional general-purpose programming languages use threads provided and scheduled by the operating system (or a rather abstract concept of “workers” that are based on OS threads) to allow you to run multiple functions concurrently.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;li&gt;Those threads usually have a stack of a few megabytes in memory meaning that you can’t spawn too many of them, for example, 1000 threads where each consumes 1 MB of memory would require 1 GB of memory already.&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;li&gt;Requesting a thread from the operating system isn’t cheap, you better take as many as you need during the initialization phase of your program and reuse them.&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;Context switches on OS threads aren’t cheap. Most registers and some caches will need to be swapped out.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;The limitations associated with OS threads make writing non-blocking concurrent systems unnecessarily difficult. &lt;b&gt;Go&lt;/b&gt; has a completely different concurrency model. In Go, you can run functions in separate so-called “&lt;a href=&quot;https://www.geeksforgeeks.org/goroutines-concurrency-in-golang/&quot; target=&quot;_blank&quot;&gt;goroutines&lt;/a&gt;”.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;Go’s goroutines have a flexible stack that’s at least 2kb in memory and it grows as needed. This means that you can literally spawn millions of them compared to only thousands of threads.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;Goroutines are multiplexed through an OS thread pool in the built-in runtime and can thus achieve 99.9% CPU utilization.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;They’re scheduled cooperatively, meaning that they return control to the built-in user-space scheduler when they’re getting blocked (by, for example, a database operation)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;Context switches on goroutines are very cheap since fewer registers need to be swapped out.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;Creating and suspending goroutines is very cheap because it’s done on the application level and doesn’t require a system-space roundtrip.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;Finally, what makes &lt;b&gt;Go&lt;/b&gt; unique in a sense, is the combination of compilation to actual binary executables, the concurrency model, the runtime, the garbage collector, and the particular qualities of the language itself.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;Limitations of GoLang&lt;/b&gt;&lt;/h2&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;One of the most notable limitations of &lt;b&gt;GoLang&lt;/b&gt; is the lack of generics, which can make code more repetitive and less abstract.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;Golang doesn&#39;t have direct support for object-oriented programming. But we can achieve &lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-oops-concepts.html&quot; target=&quot;_blank&quot;&gt;OOP&lt;/a&gt; in Go with the help of struct and interfaces.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;color: black;&quot;&gt;There is no implicit type conversion in Golang,&amp;nbsp;which can sometimes result in more explicit type casting in code.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;Reference:&lt;/span&gt;&lt;/b&gt; &lt;a href=&quot;https://go.dev/&quot; target=&quot;_blank&quot;&gt;Golang Offical Documentation&lt;/a&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/1543172019424679192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2023/08/what-is-go-programming-language.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1543172019424679192'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1543172019424679192'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2023/08/what-is-go-programming-language.html' title='What is GoLang? Introduction to Go Programming Language'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-4538379998108043459</id><published>2020-01-28T19:16:00.000+05:30</published><updated>2020-01-28T21:20:53.947+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="final vs immutable"/><title type='text'>What is the difference between final and immutable in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOFIP0sRFoHZ-YUII7gw_A0jVfRwA1FEl6Dc8-bKCnoYd0CWp1G-IZI_rRtrp78krrkpij4r_6Z3MumbbSE23Zas81oQExUFughpyLDRjcZ7JBokdNUoImIyHd1hQsJ4gndUTxQqP2Wtij/s1600/Screenshot+%2528533%2529.png%20&quot; style=&quot;display: none;&quot; /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black; font-weight: bold;&quot;&gt;Final:&lt;/b&gt; The &lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-final-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;Final&lt;/span&gt;&lt;/a&gt; in Java is a keyword that is applicable for only variables, methods, and class. The Java Final Keyword is used to restrict the user to use variables, methods, and class. The Final keyword is applicable for all the types of variables such as for instance variable, static variable, and local variable. When a variable declared as final and assigned a value, you can&#39;t change the value of the variable. The final method can&#39;t be overridden by the child class. A class that is declared final cannot be extended.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black; font-weight: bold;&quot;&gt;immutability: &lt;/b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-create-immutable-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;Immutability&lt;/span&gt;&lt;/a&gt; means once we create an object we are not allowed to change the content of that object. If any person trying to change the content if there is a change in the content with those changes a new object will be created. If there are no changes in the content existing object will be reused.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Final vs immutable in Java:&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;1. &lt;/b&gt;Final means that you can&#39;t change the object reference to point to another reference or another object, but you can still mutate its state (by using the setter method). Where immutable means that the object&#39;s actual value can&#39;t be changed, but you can change its reference to another one.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;2. &lt;/b&gt;The modifier final is applicable for&lt;span style=&quot;color: lime;&quot;&gt; &lt;a href=&quot;https://www.javastudypoint.com/2019/12/types-of-variables-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;variables&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;not for objects, Whereas immutability applicable for objects not for variables.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;3. &lt;/b&gt;Final ensures that the address of the object remains the same, Whereas the immutable suggest that we can&#39;t change the state of the object once created.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;4.&lt;/b&gt; By declaring the reference variable as final we are not going to get any immutability nature but we can perform any type of changes in the corresponding objects and we can&#39;t reassign reference variable to any new object&lt;/span&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;font-weight: bold; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Java program to demonstrate the difference between final and immutability:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;class Test{
 public static void main(String args[]){
  final StringBuffer sb = new StringBuffer(&quot;Java&quot;);
  
  //Even though reference variable is final
  //we can perform any changes to corresponding object.
  sb.append(&quot;studypoint&quot;);
  System.out.println(sb);
  
  //Here, we will get compile time error because
  //we can&#39;t reassign reference variable to any new object.
  sb = new StringBuffer(&quot;Hello Javastudypoint&quot;);
  System.out.println(sb);
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC2BADh7Pp16itIbRQ8vfMJk8fNl88YjC3sI3-mh7LQO3EwbBQ8n8zbThSWIJgbs_4C9TYURP3y2p4GL8at10YD4gWxt8wou9dulngrQfZxxjrZtBG0LY2XhyBPbmLlU2iHrAlsbqZ8tHi/s1600/Screenshot+%2528532%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;What is the difference between final and immutable in Java?&quot; border=&quot;0&quot; data-original-height=&quot;146&quot; data-original-width=&quot;705&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC2BADh7Pp16itIbRQ8vfMJk8fNl88YjC3sI3-mh7LQO3EwbBQ8n8zbThSWIJgbs_4C9TYURP3y2p4GL8at10YD4gWxt8wou9dulngrQfZxxjrZtBG0LY2XhyBPbmLlU2iHrAlsbqZ8tHi/s1600/Screenshot+%2528532%2529.png&quot; title=&quot;What is the difference between final and immutable in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;Diagrammatically representation of the above program.&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOFIP0sRFoHZ-YUII7gw_A0jVfRwA1FEl6Dc8-bKCnoYd0CWp1G-IZI_rRtrp78krrkpij4r_6Z3MumbbSE23Zas81oQExUFughpyLDRjcZ7JBokdNUoImIyHd1hQsJ4gndUTxQqP2Wtij/s1600/Screenshot+%2528533%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;What is the difference between final and immutable in Java?&quot; border=&quot;0&quot; data-original-height=&quot;246&quot; data-original-width=&quot;757&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOFIP0sRFoHZ-YUII7gw_A0jVfRwA1FEl6Dc8-bKCnoYd0CWp1G-IZI_rRtrp78krrkpij4r_6Z3MumbbSE23Zas81oQExUFughpyLDRjcZ7JBokdNUoImIyHd1hQsJ4gndUTxQqP2Wtij/s1600/Screenshot+%2528533%2529.png&quot; title=&quot;What is the difference between final and immutable in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Explanation: &lt;/b&gt;In the above diagram, we can see that we are creating an object of StringBuffer class by making the reference variable as final.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;1. By declaring a reference variable final, it does not mean that the object is immutable in nature.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;2. In the second line, we are performing &lt;b&gt;&lt;i&gt;append() &lt;/i&gt;&lt;/b&gt;operation on the created object and it is successfully changed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;3. If the object is immutable, the above operation can&#39;t be done.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;4. But it is executed successfully as we declare reference variable as final, which means we can&#39;t reassign anything to that reference variable again.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;5. Therefore when we try to create a new object of StringBuffer class then it won&#39;t be created and we will get a compile-time error.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Reference: &lt;/span&gt;&lt;/b&gt;&lt;a href=&quot;https://www.geeksforgeeks.org/final-vs-immutability-java/&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;final vs immutability in Java.&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;You may also like these posts:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/compare-two-strings-lexicographically-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;1. How to compare two strings lexicographically in Java?&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-trim-method-with-example.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;2. How to remove leading and trailing whitespaces from a string?&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-char-array-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;3. How to convert a string into a char array?&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/operators-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;4. Types of operators in Java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-oops-concepts.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;5. Java OOPs Concepts with Example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-replace-string-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;6. How to replace a string in Java?&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/4538379998108043459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/final-vs-immutable-in-java.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/4538379998108043459'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/4538379998108043459'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/final-vs-immutable-in-java.html' title='What is the difference between final and immutable in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOFIP0sRFoHZ-YUII7gw_A0jVfRwA1FEl6Dc8-bKCnoYd0CWp1G-IZI_rRtrp78krrkpij4r_6Z3MumbbSE23Zas81oQExUFughpyLDRjcZ7JBokdNUoImIyHd1hQsJ4gndUTxQqP2Wtij/s72-c/Screenshot+%2528533%2529.png%20" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-935056788997552299</id><published>2020-01-26T00:07:00.000+05:30</published><updated>2020-01-26T00:07:08.247+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="immutable class in java"/><title type='text'>How we can create our own immutable class in java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the previous tutorial, we have learned about &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt;&lt;/a&gt; class, we explore its constructors and important methods. In this tutorial, we will learn how to &lt;b&gt;create an immutable class&lt;i&gt;&lt;/i&gt;&lt;/b&gt; in java. First, before creating our own immutable class, we can recall you about what is immutability.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Immutable class means once we create an object we are not allowed to change the content of that object if any person trying to change the content if there is a change in the content with those changes a new object will be created. If there is no change in the content existing object will be reused. Now let&#39;s discuss how to create an immutable class in Java. The following rules define a simple strategy for &lt;b&gt;creating an immutable class&lt;i&gt;&lt;/i&gt;&lt;/b&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAvd2oaHv2q7nxcNF7RuIpFQ2GZ0s22eNZ38v7tWuj1ZWsUHx-vm3KDO4IWDSQmmlfggIvGfAYIHu61-oXDg0tpszSJx2uXrkVS2c7qxszPgmBceWxdU8oTKITcRwwTvXAO-5U3vS3Igw5/s1600/Screenshot+%2528530%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How we can create our own immutable class in java?&quot; border=&quot;0&quot; data-original-height=&quot;455&quot; data-original-width=&quot;641&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAvd2oaHv2q7nxcNF7RuIpFQ2GZ0s22eNZ38v7tWuj1ZWsUHx-vm3KDO4IWDSQmmlfggIvGfAYIHu61-oXDg0tpszSJx2uXrkVS2c7qxszPgmBceWxdU8oTKITcRwwTvXAO-5U3vS3Igw5/s1600/Screenshot+%2528530%2529.png&quot; title=&quot;How we can create our own immutable class in java?&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. The class must be declared as &lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-final-keyword.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;final&lt;/span&gt;&lt;/a&gt; so that it can&#39;t be extended.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. Make all the fields final and private.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;3. Don&#39;t provide &quot;setter&quot; methods — methods that modify fields or objects referred to by fields.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;4. Use getter method for all the &lt;a href=&quot;https://www.javastudypoint.com/2019/12/types-of-variables-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;variables&lt;/span&gt;&lt;/a&gt; in it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;5. Initialize all the fields via using a parameterized &lt;a href=&quot;https://www.javastudypoint.com/2018/12/constructor-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;constructor&lt;/span&gt;&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example to create an immutable class:&lt;/b&gt;&lt;/h2&gt;&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public final class Test{
	//private and final data member.
	private final int i;
	//parameterized constructor.
	Test(int i){
		this.i = i;
	}
	
	/*modify method with return type test.
	because of this modify method test 
	class becomes immutable. */
	public Test modify(int i){
		/*check current objet i value is equal to
		your provided value(passing argument in constructor). 
		if both are same no change in the content 
		therefore we return current object only. */
		if(this.i == i){
			return this;
		}
		/*if there is change in the content, create 
		a new object with updated i value and return
		that object. */
		else{
			return new Test(i);
		}
	}
	public static void main(String args[]){
		Test t1 = new Test(10);
		Test t2 = t1.modify(100);
		Test t3 = t1.modify(10);
		
		System.out.println(t1 == t2); //false
		System.out.println(t1 == t3); //true;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;You may also like these posts: &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-trim-method-with-example.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;1. How to remove leading and trailing whitespaces from a string?&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/compare-two-strings-lexicographically-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;2. How to compare two strings lexicographically in java?&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-substring-method.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;3. How to find substring in java?&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-replace-string-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;4. How to replace a string in java?&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-char-array-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;5. How to convert a string into a char array?&lt;/a&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;




</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/935056788997552299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-create-immutable-class-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/935056788997552299'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/935056788997552299'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-create-immutable-class-in-java.html' title='How we can create our own immutable class in java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAvd2oaHv2q7nxcNF7RuIpFQ2GZ0s22eNZ38v7tWuj1ZWsUHx-vm3KDO4IWDSQmmlfggIvGfAYIHu61-oXDg0tpszSJx2uXrkVS2c7qxszPgmBceWxdU8oTKITcRwwTvXAO-5U3vS3Igw5/s72-c/Screenshot+%2528530%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-4337252675078846609</id><published>2020-01-09T14:21:00.000+05:30</published><updated>2020-01-09T14:30:18.891+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String trim() method"/><title type='text'>How to remove leading and trailing whitespaces from String in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned about &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string&lt;/span&gt; &lt;/a&gt;class methods. In this tutorial, we will learn how to &lt;b style=&quot;color: black;&quot;&gt;remove leading and trailing whitespaces&lt;i&gt;&lt;/i&gt;&lt;/b&gt; &lt;b&gt;from String&lt;/b&gt;. Java String &lt;span style=&quot;color: black;&quot;&gt;trim()&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt; method is used to remove leading and trailing whitespaces from String. In this tutorial, we will learn the trim() method with a small case study. So that, you can understand &lt;b&gt;Java String trim()&lt;/b&gt;&lt;b style=&quot;color: black;&quot;&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method with much clarity. Here, we will discuss first what is the need for that method. We will explain its need with an example.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java String trim() Method&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Java String trim()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is used to remove whitespaces either from the beginning and the end of a string. It returns a copy of the string, with leading and trailing whitespace omitted. Let&#39;s understand with an example.&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
import java.util.Scanner;
class TrimExample{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		System.out.println(&quot;Enter Country Name: &quot;);
		String country = sc.nextLine();
		
		if(country.equals(&quot;india&quot;)){
			System.out.println(&quot;Capital of india is delhi&quot;);
		}
		else if(country.equals(&quot;australia&quot;)){
			System.out.println(&quot;Capital of australia is canberra&quot;);
		}
		else if(country.equals(&quot;england&quot;)){
			System.out.println(&quot;Capital of england is london&quot;);
		}
		else{
			System.out.println(&quot;Please enter a valid country name.&quot;);
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, I wrote a simple program where the user entered a country name and corresponding to the entered country name user will see a message where the country capital is printed. Let&#39;s run this program. The code compiled and run fine there is no problem at all.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8YZ2U-CqZlmi4Hvb4WmQyHEMEWOyiAgK7ocu5r5zVuEWX8P-2In23TWusSYQXfAolBT6eXKgXou0semxnAeBfTP5-WC0vOiPMUyUYv2XNrc3iao9MoM-pXx1CMNz3Z_9iD_30Irle1dan/s1600/Screenshot+%2528516%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java string trim() method&quot; border=&quot;0&quot; data-original-height=&quot;454&quot; data-original-width=&quot;680&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8YZ2U-CqZlmi4Hvb4WmQyHEMEWOyiAgK7ocu5r5zVuEWX8P-2In23TWusSYQXfAolBT6eXKgXou0semxnAeBfTP5-WC0vOiPMUyUYv2XNrc3iao9MoM-pXx1CMNz3Z_9iD_30Irle1dan/s1600/Screenshot+%2528516%2529.png&quot; title=&quot;How to remove leading and trailing whitespaces from String in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;But there are &lt;b&gt;&lt;i&gt;two biggest problems&lt;/i&gt;&lt;/b&gt; in this code from the programmer point of view.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;1.&lt;/b&gt; In this program, the end-user is responsible to enter the country name. The end-user entered the country name either lower case or upper case or mixture. But our program always considered lower case only. If the end-user entered country name only in lower case then only our program works. By mistake, if the end-user entered the country name in the upper case letter then our program will not woks. Let&#39;s see the example.&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO8jUo6AEMeZ92qhVGvsShVkOGMwbU8txblvd5ZizHR9q4dmxxcYeCNX6IbIX5DZikRgJmeUZO0T0CGQ4VOIwUmMtKzumEKrijGFhc5lcknR0oyYDj6avBnMpfBbGYXnwCAkyhagMiFLRa/s1600/Screenshot+%2528517%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java string trim() method&quot; border=&quot;0&quot; data-original-height=&quot;543&quot; data-original-width=&quot;703&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO8jUo6AEMeZ92qhVGvsShVkOGMwbU8txblvd5ZizHR9q4dmxxcYeCNX6IbIX5DZikRgJmeUZO0T0CGQ4VOIwUmMtKzumEKrijGFhc5lcknR0oyYDj6avBnMpfBbGYXnwCAkyhagMiFLRa/s1600/Screenshot+%2528517%2529.png&quot; title=&quot;How to remove leading and trailing whitespaces from String in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;There are &lt;b style=&quot;color: black;&quot;&gt;two solutions&lt;i&gt;&lt;/i&gt;&lt;/b&gt; to the above problem. First, We can replace equals() method with equalIgnoreCase(). But if in your program there are 1000 lines or 10000 lines then you need to replace &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-compare-two-strings-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;equals()&lt;/span&gt;&lt;/a&gt; method with an &lt;a href=&quot;https://www.javastudypoint.com/2020/01/equalsignorecase-in-java-string.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;equalIgnoreCase()&lt;/span&gt;&lt;/a&gt; method with 1000 or 10000 times, which is not a good practice.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The &lt;b style=&quot;color: black;&quot;&gt;&lt;i&gt;second solution&lt;/i&gt;&lt;/b&gt; is, as we know our program accepts only lower case letters. So, what we will do is, If the end-user entered the country name we will convert into a &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-into-lowercase-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;lower case&lt;/span&gt;&lt;/a&gt; letter. Then our problem will be solved. So the second solution is very easy because we need to write only one line. See the example below.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
import java.util.Scanner;
class TrimExample{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		System.out.println(&quot;Enter Country Name: &quot;);
		String country = sc.nextLine().toLowerCase();
		
		if(country.equals(&quot;india&quot;)){
			System.out.println(&quot;Capital of india is delhi&quot;);
		}
		else if(country.equals(&quot;australia&quot;)){
			System.out.println(&quot;Capital of australia is canberra&quot;);
		}
		else if(country.equals(&quot;england&quot;)){
			System.out.println(&quot;Capital of england is london&quot;);
		}
		else{
			System.out.println(&quot;Please enter a valid country name.&quot;);
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
Enter Country Name: INdia
Capital of india is delhi
Enter Country Name: ENGLand
Capital of england is london
Enter Country Name: AUSTRALIA
Capital of australia is canberra
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2.&lt;/b&gt; But still, there is one more&lt;b&gt; problem&lt;i&gt;&lt;/i&gt;&lt;/b&gt; with this code. As we know, the end-user is responsible to enter the country name. If the end-user entered the country name with &lt;b&gt;&lt;i&gt;some spaces&lt;/i&gt;&lt;/b&gt; at the starting or ending then our program check is there some spaces followed by a country name is available or not. In our code, this case is not available, then our code will not works and show a message to the end-user please enter a valid country name. Let&#39;s see the example.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuFhyRfGSV96TLZlLP1ZlMdqz5GH-t02ZiDwRP9NEizNfVZCUvDD6S8TUotylsvhPX3I_tz41l9O20qU5nC87jYZuW2ILv0g9z9vbNSXh7FsnPejphwaCYIy-do6r4yQVoHFT4gu5OxpA1/s1600/Screenshot+%2528518%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java string trim() method&quot; border=&quot;0&quot; data-original-height=&quot;535&quot; data-original-width=&quot;690&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuFhyRfGSV96TLZlLP1ZlMdqz5GH-t02ZiDwRP9NEizNfVZCUvDD6S8TUotylsvhPX3I_tz41l9O20qU5nC87jYZuW2ILv0g9z9vbNSXh7FsnPejphwaCYIy-do6r4yQVoHFT4gu5OxpA1/s1600/Screenshot+%2528518%2529.png&quot; title=&quot;How to remove leading and trailing whitespaces from String in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;To resolve this problem, What we can do, before comparing the country name if any spaces entered by the end-user either at the beginning or at the end, If we remove those spaces then our problem will be solved. We can remove spaces either at the beginning or end of the string by using the &lt;b&gt;trim()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java String trim() Method Example&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
import java.util.Scanner;
class TrimExample{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		System.out.print(&quot;Enter Country Name: &quot;);
		String country = sc.nextLine().toLowerCase().trim();
		
		if(country.equals(&quot;india&quot;)){
			System.out.println(&quot;Capital of india is delhi&quot;);
		}
		else if(country.equals(&quot;australia&quot;)){
			System.out.println(&quot;Capital of australia is canberra&quot;);
		}
		else if(country.equals(&quot;england&quot;)){
			System.out.println(&quot;Capital of england is london&quot;);
		}
		else{
			System.out.println(&quot;Please enter a valid country name.&quot;);
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
Enter Country Name:   INdia
Capital of india is delhi
Enter Country Name:    ENGLand
Capital of england is london
Enter Country Name:     AUSTRALIA
Capital of australia is canberra
&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/4337252675078846609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-trim-method-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/4337252675078846609'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/4337252675078846609'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-trim-method-with-example.html' title='How to remove leading and trailing whitespaces from String in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8YZ2U-CqZlmi4Hvb4WmQyHEMEWOyiAgK7ocu5r5zVuEWX8P-2In23TWusSYQXfAolBT6eXKgXou0semxnAeBfTP5-WC0vOiPMUyUYv2XNrc3iao9MoM-pXx1CMNz3Z_9iD_30Irle1dan/s72-c/Screenshot+%2528516%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-8785178010026284655</id><published>2020-01-08T19:30:00.000+05:30</published><updated>2020-01-08T19:30:31.176+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String compareTo()"/><title type='text'>How to Compare two Strings lexicographically in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The Java &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt;&lt;/a&gt; Class provides many ways to compare the content of the two Strings. One way to compare the content of the two strings by using the equals() method. We have learned the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-compare-two-strings-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;equals()&lt;/span&gt; &lt;/a&gt;method in our last tutorial. In this tutorial, we will learn how to &lt;b style=&quot;color: black;&quot;&gt;compare two strings lexicographically&lt;i&gt;&lt;/i&gt;&lt;/b&gt; in Java.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:inline-block;width:336px;height:280px&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;9992676996&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java String compareTo() Method&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Java String compareTo()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is used to compare the two strings lexicographically in Java. The comparison is based on the Unicode value of each character in the string. The String compareTo() method returns the positive number, negative number or 0.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;If the first string is greater than the second string lexicographically, then it returns a positive number. If the first string is smaller than the second string lexicographically, then it returns a negative number. If both the strings are equal lexicographically, then it returns 0.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNGm1IrN3nhJtIkieiprMDMSex6uscbWolNADcO80zhUBA0qJOxk7rQrXeGOhKRhtabfTrtV09GlTajlYkUN9wXsIFQiS8cjm9dokSjin6G1_qlr47IlYl_WVpCjwUOkJhXa_CncCD9jso/s1600/Screenshot+%2528512%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;compare two strings lexicographically in java&quot; border=&quot;0&quot; data-original-height=&quot;415&quot; data-original-width=&quot;636&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNGm1IrN3nhJtIkieiprMDMSex6uscbWolNADcO80zhUBA0qJOxk7rQrXeGOhKRhtabfTrtV09GlTajlYkUN9wXsIFQiS8cjm9dokSjin6G1_qlr47IlYl_WVpCjwUOkJhXa_CncCD9jso/s1600/Screenshot+%2528512%2529.png&quot; title=&quot;compare two strings lexicographically in java&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br/&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java program to compare two strings lexicographically&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;class Lexicographically{
	public static void main(String args[]){
		String str1 = &quot;Hello&quot;;
		String str2 = &quot;Hi&quot;;
		String str3 = &quot;Ram&quot;;
		String str4 = &quot;Javastudypoint&quot;;
		String str5 = &quot;Tutorial&quot;;
		String str6 = &quot;Tutorial&quot;;
		
		//-4 because &quot;e&quot; is 4 times less than &quot;i&quot;.
		System.out.println(str1.compareTo(str2));
		
		//2 because &quot;T&quot; is 2 times greater than &quot;R&quot;.
		System.out.println(str5.compareTo(str3));
		
		//-2 because &quot;H&quot; is 2 times less than &quot;J&quot;.
		System.out.println(str1.compareTo(str4));
		
		//-12 because &quot;H&quot; is 12 times less than &quot;T&quot;.
		System.out.println(str1.compareTo(str5));
		
		//0 because both the strings are equal.
		System.out.println(str5.compareTo(str6));
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
-4
2
-2
-12
0
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/8785178010026284655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/compare-two-strings-lexicographically-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8785178010026284655'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8785178010026284655'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/compare-two-strings-lexicographically-in-java.html' title='How to Compare two Strings lexicographically in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNGm1IrN3nhJtIkieiprMDMSex6uscbWolNADcO80zhUBA0qJOxk7rQrXeGOhKRhtabfTrtV09GlTajlYkUN9wXsIFQiS8cjm9dokSjin6G1_qlr47IlYl_WVpCjwUOkJhXa_CncCD9jso/s72-c/Screenshot+%2528512%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-1132824150859726070</id><published>2020-01-08T14:38:00.000+05:30</published><updated>2020-01-08T14:38:33.287+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String toCharArray()"/><title type='text'>How to Convert a String to char array in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned how to convert a string to &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-uppercase-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;uppercase&lt;/span&gt; &lt;/a&gt;in Java. We have learned all the two variants of toUpperCase in Java. In this tutorial, we will learn how to convert a &lt;b style=&quot;color: black;&quot;&gt;string to a char array&lt;i&gt;&lt;/i&gt;&lt;/b&gt; in Java. We can convert a string to char array by using the &lt;b style=&quot;color: black;&quot;&gt;toCharArray()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method of Java String class. It returns a newly allocated character &lt;a href=&quot;https://www.javastudypoint.com/2019/12/array-in-java-with-example.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;array&lt;/span&gt;&lt;/a&gt; whose length is the length of this string.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the &lt;b&gt;Java String toCharArray()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
puyblic char[] toCharArray
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;It converts this&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt; &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string &lt;/span&gt;&lt;/a&gt;&lt;/span&gt;to a new character array. 
&lt;/span&gt;&lt;br /&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java program to convert a string to char array.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class toCharArray{
	public static void main(String args[]){
		String str = &quot;Java&quot;;
		
		//converting string to char array.
		char ch[] = str.toCharArray();
		
		//printing the char array.
		for(int i=0; i&amp;lt;ch.length; i++){
			System.out.println(ch[i]);
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCQxoPY1fY-plojviCRfU0cDZUOpS3Po15pyTdq_nN7t-lsg7aC0Hxgrrak1ZmKFSIg2G4TO_S86gTUuZUIccWHy0uT8PZx3fSnmwqKBKV8w-E0eImw645Q8IuZs4-824QkdGoGr2WAVCM/s1600/Screenshot+%2528507%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How to Convert a String to char array in Java?&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;511&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCQxoPY1fY-plojviCRfU0cDZUOpS3Po15pyTdq_nN7t-lsg7aC0Hxgrrak1ZmKFSIg2G4TO_S86gTUuZUIccWHy0uT8PZx3fSnmwqKBKV8w-E0eImw645Q8IuZs4-824QkdGoGr2WAVCM/s1600/Screenshot+%2528507%2529.png&quot; title=&quot;How to Convert a String to char array in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/1132824150859726070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-char-array-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1132824150859726070'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1132824150859726070'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-char-array-in-java.html' title='How to Convert a String to char array in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCQxoPY1fY-plojviCRfU0cDZUOpS3Po15pyTdq_nN7t-lsg7aC0Hxgrrak1ZmKFSIg2G4TO_S86gTUuZUIccWHy0uT8PZx3fSnmwqKBKV8w-E0eImw645Q8IuZs4-824QkdGoGr2WAVCM/s72-c/Screenshot+%2528507%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-8739650645413659572</id><published>2020-01-08T12:56:00.002+05:30</published><updated>2020-01-08T12:56:58.008+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String toUpperCase()"/><title type='text'>How to Convert a String to UpperCase in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned how to convert a string into a &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-into-lowercase-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;lowercase &lt;/span&gt;&lt;/a&gt;in Java. We discussed all the two variants to convert all the characters of a string to uppercase. In this tutorial, we will learn how to convert a &lt;b style=&quot;color: black;&quot;&gt;string to UpperCase in Java&lt;i&gt;&lt;/i&gt;&lt;/b&gt;. We can convert all the characters of a string to UpperCase by using the &lt;b style=&quot;color: black;&quot;&gt;toUpperCase()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method of Java String Class. Like, toLowerCase() method the toUpperCase() method also has two variants. In this tutorial, we will discuss all the two variants of the toUpperCase() method.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;1. toUpperCase():&lt;/b&gt; This is the first variant of &lt;b style=&quot;color: black;&quot;&gt;toUpperCase() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method of &lt;span style=&quot;color: lime;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;class. This method converts all the characters of a string to UpperCase. This method is equivalent to toUpperCase(Locale.getDefault).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the first variant of the &lt;b&gt;toUpperCase() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method is given below:&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;public String toUpperCase()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;Java program to convert a string to UpperCase&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;class toUpperCase{
	public static void main(String args[]){
		String str = &quot;String Tutorial BY JavaStudyPoint&quot;;
		//converting all the characters of
		//a string into uppercase.
		System.out.println(str.toUpperCase());
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
STRING TUTORIAL BY JAVASTUDYPOINT
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. toUpperCase(Locale locale): &lt;/b&gt;This is the second variant of the &lt;b&gt;Java String toUpperCase()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. This method converts all the characters of a string to UpperCase using to rule of a given&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt; &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;locale&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the second variant of the &lt;b&gt;toUpperCase()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String toUpperCase(Locale locale)
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String toUpperCase(Locale locale) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
import java.util.Locale;
class toUpperCase{
	public static void main(String args[]){
		String str = &quot;String Tutorial BY JavaStudyPoint&quot;;
		
		//Locales with the language &quot;tr&quot;
		//for turkish and &quot;en&quot; for english.
		Locale turkish = Locale.forLanguageTag(&quot;tr&quot;);
		Locale english = Locale.forLanguageTag(&quot;en&quot;);
		
		//converting string str into lowercase
		//using turkish and english language.
		String str1 = str.toUpperCase(turkish);
		String str2 = str.toUpperCase(english);
		System.out.println(str1);
		System.out.println(str2);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVZamyf6LU3Rt5sFXshizGlcGa6flZ7iBVXp7WSo5wlU7ShgwlfRcOYEaY6SxP228hMQ9PzWXLGe0H5bXPUAQIeMK5-wuAPBN_ltOsSnKcZi1fh9LZqSgQi2N9W4OEJErPDpHL4l78Usx3/s1600/Screenshot+%2528505%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;how to convert a string to uppercase in java&quot; border=&quot;0&quot; data-original-height=&quot;280&quot; data-original-width=&quot;713&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVZamyf6LU3Rt5sFXshizGlcGa6flZ7iBVXp7WSo5wlU7ShgwlfRcOYEaY6SxP228hMQ9PzWXLGe0H5bXPUAQIeMK5-wuAPBN_ltOsSnKcZi1fh9LZqSgQi2N9W4OEJErPDpHL4l78Usx3/s1600/Screenshot+%2528505%2529.png&quot; title=&quot;how to convert a string to uppercase in java&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/8739650645413659572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-uppercase-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8739650645413659572'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8739650645413659572'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-uppercase-in-java.html' title='How to Convert a String to UpperCase in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVZamyf6LU3Rt5sFXshizGlcGa6flZ7iBVXp7WSo5wlU7ShgwlfRcOYEaY6SxP228hMQ9PzWXLGe0H5bXPUAQIeMK5-wuAPBN_ltOsSnKcZi1fh9LZqSgQi2N9W4OEJErPDpHL4l78Usx3/s72-c/Screenshot+%2528505%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-155351029310557010</id><published>2020-01-07T22:07:00.004+05:30</published><updated>2020-01-08T12:58:03.269+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String toLowerCase()"/><title type='text'>How to Convert a String into Lowercase in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned Java String&#39;s &lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-lastindexof-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;lastIndexOf()&lt;/span&gt; &lt;/a&gt;method. We have learned all the four variants of this method with an example. In this tutorial, we will learn how to convert a &lt;b style=&quot;color: black;&quot;&gt;string into lowercase&lt;i&gt;&lt;/i&gt;&lt;/b&gt; in java. We can convert all the characters of a string into lowercase by using the &lt;b style=&quot;color: black;&quot;&gt;toLowerCase()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method of Java String Class. There are two variants of the &lt;b style=&quot;color: black;&quot;&gt;toLowerCase() method in Java.&lt;i&gt;&lt;/i&gt;&lt;/b&gt; In this tutorial, we will discuss all the two variants of this method.&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;

&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;1. toLowerCase(): &lt;/b&gt;This is the first variant of &lt;b style=&quot;color: black;&quot;&gt;toLowerCase() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method of &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string&lt;/span&gt;&lt;/a&gt; class. This method converts all the characters of a string into lowercase. This is equivalent to calling toLowerCase(Locale.getDefault).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the first variant of the &lt;b&gt;toLowerCase() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method is given below:&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;public String toLowerCase()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;Java program to convert a given string into lowercase&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;class toLowerCase{
	public static void main(String args[]){
		String str = &quot;String Tutorial BY JavaStudyPoint&quot;;
		//converting all the characters of 
		//a string into lowecase.
		System.out.println(str.toLowerCase());
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
string tutorial by javastudypoint
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. toLowerCase(Locale locale): &lt;/b&gt;This is the second variant of the &lt;b&gt;Java String toLowerCase()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. It converts all the characters in this String to lower case using the rule of the given &lt;span style=&quot;color: lime;&quot;&gt;&lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;locale&lt;/span&gt;&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the second variant of the &lt;b&gt;toLowerCase()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String toLowerCase(Locale locale)
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String toLowerCase(Locale locale) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
import java.util.Locale;
class toLowerCase{
	public static void main(String args[]){
		String str = &quot;StrIng TutorIal BY JavaStudyPoint&quot;;
		
		//Locales with the language &quot;tr&quot;
		//for turkish and &quot;en&quot; for english.
		Locale turkish = Locale.forLanguageTag(&quot;tr&quot;);
		Locale english = Locale.forLanguageTag(&quot;en&quot;);
		
		//converting string str into lowercase
		//using turkish and english language.
		String str1 = str.toLowerCase(turkish);
		String str2 = str.toLowerCase(english);
		System.out.println(str1);
		System.out.println(str2);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIv1OfduFIL1Z3viRfU8RjoUuLijunz5GcWJCUNnzMP8dCBmg1tat6Z2Ov7XYZpkLXhPBt1_x6h76ffeGe0ijVDRV6pbUxC0HGedKgvOhL-s-QhTc3qnKt0f3KaJJzMVSbF47z5IoLhMC5/s1600/Screenshot+%2528504%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;how to convert a string into lowercase in java&quot; border=&quot;0&quot; data-original-height=&quot;279&quot; data-original-width=&quot;703&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIv1OfduFIL1Z3viRfU8RjoUuLijunz5GcWJCUNnzMP8dCBmg1tat6Z2Ov7XYZpkLXhPBt1_x6h76ffeGe0ijVDRV6pbUxC0HGedKgvOhL-s-QhTc3qnKt0f3KaJJzMVSbF47z5IoLhMC5/s1600/Screenshot+%2528504%2529.png&quot; title=&quot;how to convert a string into lowercase in java&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/155351029310557010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-convert-a-string-into-lowercase-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/155351029310557010'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/155351029310557010'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-convert-a-string-into-lowercase-in-java.html' title='How to Convert a String into Lowercase in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIv1OfduFIL1Z3viRfU8RjoUuLijunz5GcWJCUNnzMP8dCBmg1tat6Z2Ov7XYZpkLXhPBt1_x6h76ffeGe0ijVDRV6pbUxC0HGedKgvOhL-s-QhTc3qnKt0f3KaJJzMVSbF47z5IoLhMC5/s72-c/Screenshot+%2528504%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-6389559685815778343</id><published>2020-01-07T16:07:00.000+05:30</published><updated>2020-01-07T16:07:15.214+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String lastIndexOf()"/><title type='text'>Java String lastIndexOf() Method with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned all about Java String&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt; &lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-indexof-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;indexOf() &lt;/span&gt;&lt;/a&gt;&lt;/span&gt;method. We discussed all the four variants of the indexOf() method. In this tutorial, we will learn about the &lt;b style=&quot;color: black;&quot;&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. There are four variants of the lastIndexOf() method. Here, we will discuss all the four variants of the Java &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt; &lt;/a&gt;lastIndexOf() method. Let&#39;s discuss these four variants one by one.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9ajMgnLPiiAr61pMfiGidX2__5JceF0IWtyKr5u4uahoSX_oGjqg7VXznpbfrR8pVZjNYGieaZxbIjXWic9rKCZmBTH11m7AHYoawcOws5wOaVk7kkI5xV5T_eRLSG4y_IFAnXYY_8u6a/s1600/Screenshot+%2528501%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java String lastIndexOf() Method with Example&quot; border=&quot;0&quot; data-original-height=&quot;465&quot; data-original-width=&quot;616&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9ajMgnLPiiAr61pMfiGidX2__5JceF0IWtyKr5u4uahoSX_oGjqg7VXznpbfrR8pVZjNYGieaZxbIjXWic9rKCZmBTH11m7AHYoawcOws5wOaVk7kkI5xV5T_eRLSG4y_IFAnXYY_8u6a/s1600/Screenshot+%2528501%2529.png&quot; title=&quot;Java String lastIndexOf() Method with Example&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;1. lastIndexOf(int ch): &lt;/b&gt;This is the first variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. This method returns the index of the last occurrence of the specified character. If the specified character is not present there, then it will return -1.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the first variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
public String lastIndexOf(int ch)
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;ch &lt;i&gt;&lt;/i&gt;&lt;/b&gt;is a character whose index we want to return.&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:inline-block;width:336px;height:280px&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;9992676996&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String lastIndexOf(int ch) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class lastIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial by javastudypoint&quot;;
	    //returns the last index
		//of specified character.
		System.out.println(str.lastIndexOf(&#39;i&#39;)); //30
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
30
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. lastIndexOf(int ch, int fromIndex): &lt;/b&gt;This is the second variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. This method returns the index of the first occurrence of the specified character, starting the search from the backward specified index. This method return -1 if the specified character is not present there.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the second variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String lastIndexOf(int ch, int fromIndex)
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;ch &lt;i&gt;&lt;/i&gt;&lt;/b&gt;is a character and&lt;b&gt; fromIndex&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is the index position at which point the search begins.
&lt;/span&gt;&lt;br /&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String lastIndexOf(int ch, int fromIndex) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class lastIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial by javastudypoint&quot;;
	    //returns the last index
		//of &#39;i&#39; before 15th index.
		System.out.println(str.lastIndexOf(&#39;i&#39;, 15)); //12
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
12
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;3. lastIndexOf(String str):&lt;/b&gt; This is the third variant of&lt;b style=&quot;color: black;&quot;&gt; Java String lastIndexOf() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method. This method returns the index of the last occurrence of the specified &lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-substring-method.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;substring&lt;/span&gt;&lt;/a&gt;. If the specified substring is not present there, it will return -1.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the third variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String lastIndexOf(String str)
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;str &lt;i&gt;&lt;/i&gt;&lt;/b&gt;is a substring whose index we want to return
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String lastIndexOf(String str) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class lastIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial in java by javastudypoint&quot;;
	    //returns the last index of
		//initial character of substring.
		System.out.println(str.lastIndexOf(&quot;java&quot;)); //27
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
27
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;4. lastIndexOf(String str, int fromIndex): &lt;/b&gt;This is the fourth variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. This method returns the index of the first occurrence of the specified substring, starting the search from the backward specified index. This method return -1 if the specified substring is not present there.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Syntax&lt;/b&gt; &lt;span style=&quot;color: black;&quot;&gt;The syntax of the fourth variant of &lt;b&gt;Java String lastIndexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String lastIndexOf(String str, int fromIndex)
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;str&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is a substring and &lt;b&gt;fromIndex&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is the index position at which point the search begins.
&lt;br /&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;1293905187&quot;
     data-ad-format=&quot;auto&quot;
     data-full-width-responsive=&quot;true&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String lastIndexOf(String str, int fromIndex) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class lastIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial in java by javastudypoint&quot;;
	    //returns the last index of
		//initial character of substring
		//before index 30.
		System.out.println(str.lastIndexOf(&quot;java&quot;, 30)); //27
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
27
&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/6389559685815778343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-lastindexof-method-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/6389559685815778343'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/6389559685815778343'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-lastindexof-method-with-example.html' title='Java String lastIndexOf() Method with Example'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9ajMgnLPiiAr61pMfiGidX2__5JceF0IWtyKr5u4uahoSX_oGjqg7VXznpbfrR8pVZjNYGieaZxbIjXWic9rKCZmBTH11m7AHYoawcOws5wOaVk7kkI5xV5T_eRLSG4y_IFAnXYY_8u6a/s72-c/Screenshot+%2528501%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-1130437139661052757</id><published>2020-01-07T12:55:00.000+05:30</published><updated>2020-01-07T12:56:14.069+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="String indexOf() method"/><title type='text'>Java String indexOf() Method with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned how to find &lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-substring-method.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;substring&lt;/span&gt;&lt;/a&gt; in java. We discussed all the two methods to find the substring in java. In this tutorial, we will learn the &lt;b style=&quot;color: black;&quot;&gt;string indexOf() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method with an example. The&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt; &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;class provides four variants of the indexOf() method. Here, we will discuss all the four variants of the &lt;b style=&quot;color: black;&quot;&gt;Java String indexOf() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method. Let&#39;s discuss one by one.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZT5_ZYwT1w7RuYy5qQ3RxuDD8NAOyNYUBAQdWDMrx85LPcZolOWF35YCYufgbqj9pUdpBCsNSsPqq3sVFsDXNjPdcyIex9Tsy1C1HXchzjmGuVFlJDkKYEXX3oftPpR02yRu4ADufOKAK/s1600/Screenshot+%2528500%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java String indexOf() methods&quot; border=&quot;0&quot; data-original-height=&quot;449&quot; data-original-width=&quot;581&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZT5_ZYwT1w7RuYy5qQ3RxuDD8NAOyNYUBAQdWDMrx85LPcZolOWF35YCYufgbqj9pUdpBCsNSsPqq3sVFsDXNjPdcyIex9Tsy1C1HXchzjmGuVFlJDkKYEXX3oftPpR02yRu4ADufOKAK/s1600/Screenshot+%2528500%2529.png&quot; title=&quot;Java String indexOf() methods&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;1. indexOf(int ch): &lt;/b&gt;This is the first variant of the Java String &lt;b&gt;indexOf() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method. This method returns the index of the first occurrence of the specified character. If the specified character is not present there then it will return -1.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the first variant of the &lt;b&gt;indexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;public int indexOf(int ch)&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;ch&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is a character whose index we want to return.&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java String indexOf(int ch) Method Example&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial by javastudypoint&quot;;
	    //returns index of first
		//occurrence of a.
		System.out.println(str.indexOf(&#39;a&#39;)); //13
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
13
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. indexOf(int ch, int fromIndex): &lt;/b&gt;This is the second variant of the &lt;b&gt;Java String indexOf() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method. This method returns the index of the first occurrence of the specified character, starting the search from the specified index. If the specified character is not present there then it will return -1.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the second variant of the &lt;b&gt;indexOf()&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public int indexOf(int ch, int fromIndex)&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;ch &lt;i&gt;&lt;/i&gt;&lt;/b&gt;is a character and &lt;b&gt;fromIndex&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is the index position at which point the search begins.&lt;/span&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String indexOf(int ch, int fromIndex) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial by javastudypoint&quot;;
	    //returns index of a
		//after 15th index at position.
		System.out.println(str.indexOf(&#39;a&#39;, 15)); //20
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;20
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;


&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;3. indexOf(String str): &lt;/b&gt;This is the third variant of the Java String &lt;b&gt;indexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. This method returns the index of the first occurrence of the specified substring. If the specified substring is not present there then it will return -1.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the third variant of the Java String &lt;b&gt;indexOf() &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;public String indexOf(String str)
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;


&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here, &lt;b&gt;str &lt;i&gt;&lt;/i&gt;&lt;/b&gt;is a substring whose index we want to return.
&lt;/span&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java String indexOf(String str) Method Example&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial by javastudypoint&quot;;
	    //returns the index of 
		//initial character of substring 
		System.out.println(str.indexOf(&quot;java&quot;)); //19
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
19
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;4. indexOf(String str, int fromIndex): &lt;/b&gt;This is the fourth variant of the &lt;b&gt;indexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. This method returns the index of the first occurrence of the specified substring, starting the search from the specified index. If the specified substring is not present there then it will return -1.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the fourth variant of the &lt;b&gt;indexOf()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String indexOf(String str, int fromIndex)
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here,&lt;b&gt; str&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is a substring and &lt;b&gt;fromIndex&lt;i&gt;&lt;/i&gt;&lt;/b&gt; is the index position at which point the search begins.&lt;/span&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String indexOf(String str, int fromIndex) Method Example&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringIndexOf{
	public static void main(String args[]){
		String str = &quot;String tutorial in java by javastudypoint&quot;;
	    //returns the index of initial character  
		//of substring after 20th position
		System.out.println(str.indexOf(&quot;java&quot;, 20)); //27
		
		//returns -1 because specified substring	
		//is not present there. 
		System.out.println(str.indexOf(&quot;Java Tutorial&quot;, 10)); //-1
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;27
-1
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/1130437139661052757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-indexof-method-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1130437139661052757'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1130437139661052757'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-indexof-method-with-example.html' title='Java String indexOf() Method with Example'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZT5_ZYwT1w7RuYy5qQ3RxuDD8NAOyNYUBAQdWDMrx85LPcZolOWF35YCYufgbqj9pUdpBCsNSsPqq3sVFsDXNjPdcyIex9Tsy1C1HXchzjmGuVFlJDkKYEXX3oftPpR02yRu4ADufOKAK/s72-c/Screenshot+%2528500%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-5124156260573292426</id><published>2020-01-06T17:38:00.000+05:30</published><updated>2020-01-06T17:38:31.337+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java substring() method"/><title type='text'>Java String substring() method with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we will learn how to find &lt;b style=&quot;color: black;&quot;&gt;substring in Java&lt;i&gt;&lt;/i&gt;&lt;/b&gt;. Basically, there are two forms of the substring method is used to find the substring in Java. In the previous tutorial, we have learned the first form of the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-find-substring-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;substring&lt;/span&gt;&lt;/a&gt; method. The first of the &lt;b style=&quot;color: black;&quot;&gt;substring(int startIndex)&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method, returns a substring from the specified index to the end of the string. But if you want to return a string that allows you to specify both the beginning and ending index of the substring, then we should go for the second form of the substring method.&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:inline-block;width:336px;height:280px&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;9992676996&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The second form of the &lt;b&gt;substring(int startIndex, int endIndex) &lt;i&gt;&lt;/i&gt;&lt;/b&gt;method returns a new&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt; &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; that is a substring of this string. The substring begins at the specified startIndex and extends to the character at index endIndex-1. Like the first form of the substring(int startIndex) method, it throws &lt;b style=&quot;color: black;&quot;&gt;StringIndexOutOfBoundsException&lt;i&gt;&lt;/i&gt;&lt;/b&gt; if the startIndex is negative, or endIndex is larger than the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-find-string-length-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;length&lt;/span&gt;&lt;/a&gt; of this String object, or startIndex is larger than endIndex.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax: &lt;/b&gt;The syntax of the second form of the substring method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
public String substring(int startIndex, int endIndex)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b style=&quot;color: black;&quot;&gt;startIndex &lt;i&gt;&lt;/i&gt;&lt;/b&gt;specifies the beginning index, and the &lt;b style=&quot;color: black;&quot;&gt;endIndex&lt;i&gt;&lt;/i&gt;&lt;/b&gt; specifies the stopping point.
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;color: black; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Java substring() Method:&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;class SubString{
	public static void main(String args[]){
		String str = &quot;String Tutorial by Javastudypoint is best&quot;;
		//returns a new string from specified
		//starting index to ending index.
		//returns Tutorial by Javastudypoint
		System.out.println(str.substring(7,33));
		
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
Tutorial by Javastudypoint
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Note:&lt;/b&gt; Remember that it &lt;a href=&quot;https://www.javastudypoint.com/2019/01/exception-handling-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;throws&lt;/span&gt;&lt;/a&gt; &lt;b style=&quot;color: black;&quot;&gt;StringIndexOutOfBoundsException &lt;i&gt;&lt;/i&gt;&lt;/b&gt;if the startIndex is negative, or endIndex is larger than the length of this String object, or startIndex is larger than endIndex. Let&#39;s see the example:
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
class SubString{
	public static void main(String args[]){
		String str = &quot;String Tutorial by Javastudypoint is best&quot;;
	      //throws exception because in this case
		//starting index is larger than 
		//ending index.
		System.out.println(str.substring(33,7));
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: black; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV8mRNyY35x3sZW_qP5mw_uEQRLz7Ky7vSkWZ36mlPwiDj9FgViVzvZlHIECpRuU_3X5GiPtQw5iDr4A4Ur9z5l_mXlQs4uQ6m2Qo4pRQBl8nXofj2wiiQ3lumJUyZp6xcusv289fe3zgl/s1600/Screenshot+%2528499%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java string substring() method with example&quot; border=&quot;0&quot; data-original-height=&quot;223&quot; data-original-width=&quot;1111&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV8mRNyY35x3sZW_qP5mw_uEQRLz7Ky7vSkWZ36mlPwiDj9FgViVzvZlHIECpRuU_3X5GiPtQw5iDr4A4Ur9z5l_mXlQs4uQ6m2Qo4pRQBl8nXofj2wiiQ3lumJUyZp6xcusv289fe3zgl/s1600/Screenshot+%2528499%2529.png&quot; title=&quot;Java string substring() method &quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/5124156260573292426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-substring-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/5124156260573292426'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/5124156260573292426'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-substring-method.html' title='Java String substring() method with Example'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV8mRNyY35x3sZW_qP5mw_uEQRLz7Ky7vSkWZ36mlPwiDj9FgViVzvZlHIECpRuU_3X5GiPtQw5iDr4A4Ur9z5l_mXlQs4uQ6m2Qo4pRQBl8nXofj2wiiQ3lumJUyZp6xcusv289fe3zgl/s72-c/Screenshot+%2528499%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-6512737026531656432</id><published>2020-01-06T15:16:00.000+05:30</published><updated>2020-01-06T15:16:10.588+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="substring in java"/><title type='text'>How to find substring in Java | Java substring() Method</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Because String objects are &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;immutable&lt;/span&gt;&lt;/a&gt;, whenever you want to modify a String, you must either copy it into a StringBuffer or use one of the following String methods. which will construct a new copy of the string with your modifications complete. In this tutorial, we will learn how to find &lt;b style=&quot;color: black;&quot;&gt;substring in Java&lt;i&gt;&lt;/i&gt;&lt;/b&gt;. A substring is a part of the string. The &lt;b style=&quot;color: black;&quot;&gt;substring(int startIndex)&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method of the String class is used to find the substring in &lt;a href=&quot;https://www.javastudypoint.com/2019/01/what-is-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;java&lt;/span&gt;&lt;/a&gt;. There are two forms of the substring method. Here, we can discuss only the first form and we will discuss the second form in our next tutorial. It throws &lt;b style=&quot;color: black;&quot;&gt;StringIndexOutOfBoundsException&lt;i&gt;&lt;/i&gt;&lt;/b&gt; if the specified index is negative or larger than the length of this String object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the &lt;b&gt;substring(int startIndex)&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method in java is given below:&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
public String substring(int startIndex)&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here,&lt;b&gt; startIndex &lt;i&gt;&lt;/i&gt;&lt;/b&gt;specifies the index at which the substring will begin. It returns a new string that is a substring of this string. It returns the string from the specified index to the end of the string.&lt;/span&gt;&lt;br /&gt;
&lt;br/&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Substring in Java:&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;class SubString{
	public static void main(String args[]){
		String str = &quot;String Tutorial by Javastudypoint&quot;;
		//returns Tutorial by Javastudypoint.
		System.out.println(str.substring(7));
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
Tutorial by Javastudypoint&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Note:&lt;/b&gt; Remember that, this method&lt;a href=&quot;https://www.javastudypoint.com/2019/01/exception-handling-in-java.html&quot; target=&quot;_blank&quot;&gt; &lt;span style=&quot;color: lime;&quot;&gt;throws &lt;/span&gt;&lt;/a&gt;&lt;b style=&quot;color: black;&quot;&gt;StringIndexOutOfBoundsException&lt;i&gt;&lt;/i&gt;&lt;/b&gt; if the specified index is negative or larger than the length of the string. Let&#39;s see the example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class SubString{
	public static void main(String args[]){
		String str = &quot;String Tutorial by Javastudypoint&quot;;
		//throws StringIndexOutOfBoundsException
		//if specified index is negative or 
		//larger than the length of the string.
		System.out.println(str.substring(-1));
		
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifalJ358b8KANdXrzA-cZTtdgkSR6k38cuMpGE_bsg-8h9uh65fzJ_d9yiw7SyvO7EfJ8FAos6r5QPQrkynb-QXwWY2neDExUr5W6m3_H7ejaChCX3FadzTLWsX9QXBQY1eaDxQljYH0Kc/s1600/Screenshot+%2528498%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;substring in java&quot; border=&quot;0&quot; data-original-height=&quot;307&quot; data-original-width=&quot;1096&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifalJ358b8KANdXrzA-cZTtdgkSR6k38cuMpGE_bsg-8h9uh65fzJ_d9yiw7SyvO7EfJ8FAos6r5QPQrkynb-QXwWY2neDExUr5W6m3_H7ejaChCX3FadzTLWsX9QXBQY1eaDxQljYH0Kc/s1600/Screenshot+%2528498%2529.png&quot; title=&quot;StringIndexOutOfBoundsException in substring method&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/6512737026531656432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-find-substring-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/6512737026531656432'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/6512737026531656432'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-find-substring-in-java.html' title='How to find substring in Java | Java substring() Method'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifalJ358b8KANdXrzA-cZTtdgkSR6k38cuMpGE_bsg-8h9uh65fzJ_d9yiw7SyvO7EfJ8FAos6r5QPQrkynb-QXwWY2neDExUr5W6m3_H7ejaChCX3FadzTLWsX9QXBQY1eaDxQljYH0Kc/s72-c/Screenshot+%2528498%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-1478362464742252363</id><published>2020-01-04T17:01:00.002+05:30</published><updated>2020-01-04T17:01:56.412+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="replace a string in java"/><title type='text'>How to replace a String in Java? | replace() vs replaceAll() vs replaceFirst()</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned how to find the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-find-string-length-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;length&lt;/a&gt; of the string in java. In this tutorial, we will learn how to &lt;b&gt;replace a string in java&lt;i&gt;&lt;/i&gt;&lt;/b&gt;. The replace() method of String class is used to replace all the occurrences of an old character in this string with a new character.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Syntax:&lt;/b&gt; The syntax of the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string&lt;/span&gt; &lt;/a&gt;&lt;b style=&quot;color: black;&quot;&gt;&lt;i&gt;replace() &lt;/i&gt;&lt;/b&gt;method is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String replace(char oldChar, char newChar)&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;b&gt;oldChar&lt;i&gt;&lt;/i&gt;&lt;/b&gt; specifies the characters to be replaced by the character specified by &lt;b&gt;newChar&lt;i&gt;&lt;/i&gt;&lt;/b&gt;.
&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:inline-block;width:336px;height:280px&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;9992676996&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/div&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Java String replace() Method:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringReplace{
	public static void main(String args[]){
		String str1  = &quot;Streng Tutoreal&quot;;
		//replacing e with i.
		System.out.println(str1.replace(&#39;e&#39;, &#39;i&#39;));
	}
}&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
String Tutorial &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;replaceAll() method in Java
&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;This method returns a String replaces each substring with this string that matches given regular expression with the given replacement.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the &lt;b&gt;replaceAll()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String replaceAll(String regex, String replacement)
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of replaceAll() method in Java:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringReplace{
	public static void main(String args[]){
		String str1  = &quot;String Tutorial is javastudypoint&quot;;
		//replacing all the occurencres of is with by.
		System.out.println(str1.replaceAll(&quot;is&quot;, &quot;by&quot;));
		//removing all the whitespaces.
		System.out.println(str1.replaceAll(&quot;\\s&quot;,&quot;&quot;));
	}
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
String Tutorial by javastudypoint
StringTutorialisjavastudypoint.
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Remember that, it throws &lt;b&gt;PatternSyntaxException&lt;i&gt;&lt;/i&gt;&lt;/b&gt; if the regular expression syntax is invalid. Let&#39;s see the example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringReplace{
	public static void main(String args[]){
		String str1  = &quot;String Tutorial is javastudypoint&quot;;
		//throws PatternSyntaxException
		System.out.println(str1.replaceAll(&quot;[&quot;, &quot;&quot;));
	}
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHp07weQ_z8Z6OPq9cq16891lQGtOAS1N9ERPDX621p6zZrua17dExoQTnFxuZcsRgeuZNmcW1ispAQKDYLDvo5AeQPoPgTjpsvkGRxh4XpFSdZhXnqLjOW8zu8zuXmXoCD8d5NWZxutTh/s1600/Screenshot+%2528497%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;replace a string in java&quot; border=&quot;0&quot; data-original-height=&quot;338&quot; data-original-width=&quot;1177&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHp07weQ_z8Z6OPq9cq16891lQGtOAS1N9ERPDX621p6zZrua17dExoQTnFxuZcsRgeuZNmcW1ispAQKDYLDvo5AeQPoPgTjpsvkGRxh4XpFSdZhXnqLjOW8zu8zuXmXoCD8d5NWZxutTh/s1600/Screenshot+%2528497%2529.png&quot; title=&quot;PatternSyntaxException in java&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br/&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;replaceFirst() method in Java&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;This method is used to replaces the first substring of this string that matches the given regular expression with the given replacement. It throws &lt;b&gt;PatternSyntaxException&lt;i&gt;&lt;/i&gt;&lt;/b&gt; if the regular expression is invalid.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax: &lt;/b&gt;The syntax of the &lt;b&gt;replaceFirst()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public String replaceFirst(String regex, String replacement)
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of replaceFirst() method in Java:&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringReplace{
	public static void main(String args[]){
		String str1  = &quot;String Tutorial by author&quot;;
		//repalces first occuerence of author with Prashant.
		System.out.println(str1.replaceFirst(&quot;author&quot;,&quot;Prashant&quot;));
	}
}&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
String Tutorial by Prashant
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/1478362464742252363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-replace-string-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1478362464742252363'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1478362464742252363'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-replace-string-in-java.html' title='How to replace a String in Java? | replace() vs replaceAll() vs replaceFirst()'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHp07weQ_z8Z6OPq9cq16891lQGtOAS1N9ERPDX621p6zZrua17dExoQTnFxuZcsRgeuZNmcW1ispAQKDYLDvo5AeQPoPgTjpsvkGRxh4XpFSdZhXnqLjOW8zu8zuXmXoCD8d5NWZxutTh/s72-c/Screenshot+%2528497%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-8885549191987483201</id><published>2020-01-04T12:22:00.000+05:30</published><updated>2020-01-04T12:22:34.736+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String length() method"/><title type='text'>How to find String length in Java using length method?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned how to check a string&lt;span style=&quot;color: lime;&quot;&gt; &lt;span style=&quot;color: lime;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-isempty-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;is empty&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;or not. In this tutorial, we will learn how to find the &lt;i style=&quot;color: black;&quot;&gt;&lt;b&gt;string length in java&lt;/b&gt;&lt;/i&gt;. We can find string length in java using the &lt;b style=&quot;color: black;&quot;&gt;length()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method of the String class. This method returns the length of the string. Remember that the length variable is used in the &lt;a href=&quot;https://www.javastudypoint.com/2019/12/array-in-java-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;array&lt;/span&gt;&lt;/a&gt; whereas the length() method is used in the string. If you try to use the length variable to find the string length then complier will get a compile-time error.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Syntax:&lt;/b&gt; The syntax of the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string &lt;/span&gt;&lt;/a&gt;class length() method is given below:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
public int length()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of Java String length() Method:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringLength{
	public static void main(String args[]){
		String str1 = &quot;Javastudypoint&quot;;
		String str2 = &quot;Prashant&quot;;
		//14 is the length of the str1.
		System.out.println(&quot;The length of the str1 is: &quot;+str1.length());
		//8 is the length of the str2.
		System.out.println(&quot;The length of the str2 is: &quot;+str2.length());
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
The length of the str1 is: 14
The length of the str2 is: 8
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Let&#39;s see an example of what happened if we are using &lt;b&gt;&lt;i&gt;length variable&lt;/i&gt;&lt;/b&gt; instead of length() method in case of a string.&amp;nbsp; If you do so, then the compiler will get a compile-time error saying cannot find the symbol. Let&#39;s see the example.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringLength{
	public static void main(String args[]){
		String str1 = &quot;Javastudypoint&quot;;
		String str2 = &quot;Prashant&quot;;
		//using length variable instead of length().
		System.out.println(&quot;The length of the str1 is: &quot;+str1.length);
		//using length variable instead of length().
		System.out.println(&quot;The length of the str2 is: &quot;+str2.length);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix51sXE6GWpWBHLNmH1Ze_HpS8MiqljIhhQM7cGyRSEoSYHS2jAmOq1oimUcufebnKLC8X589OORwIJZgVlp2e_s37us5cGC-nZcNChF2blMNvpBTEDcdAwLF5CDvIXcBEJJhjQrPg9Ba-/s1600/Screenshot+%2528496%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;string length method in java&quot; border=&quot;0&quot; data-original-height=&quot;453&quot; data-original-width=&quot;750&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix51sXE6GWpWBHLNmH1Ze_HpS8MiqljIhhQM7cGyRSEoSYHS2jAmOq1oimUcufebnKLC8X589OORwIJZgVlp2e_s37us5cGC-nZcNChF2blMNvpBTEDcdAwLF5CDvIXcBEJJhjQrPg9Ba-/s1600/Screenshot+%2528496%2529.png&quot; title=&quot;how to find string length in java using length method?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/8885549191987483201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-find-string-length-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8885549191987483201'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8885549191987483201'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-find-string-length-in-java.html' title='How to find String length in Java using length method?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix51sXE6GWpWBHLNmH1Ze_HpS8MiqljIhhQM7cGyRSEoSYHS2jAmOq1oimUcufebnKLC8X589OORwIJZgVlp2e_s37us5cGC-nZcNChF2blMNvpBTEDcdAwLF5CDvIXcBEJJhjQrPg9Ba-/s72-c/Screenshot+%2528496%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-8714309695985606027</id><published>2020-01-03T23:24:00.000+05:30</published><updated>2020-01-09T17:32:00.433+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java isEmpty() method"/><title type='text'>Java String isempty() method with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, we have learned how to compare two &lt;a href=&quot;https://www.javastudypoint.com/2020/01/equalsignorecase-in-java-string.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;strings&lt;/span&gt;&lt;/a&gt; in Java. In this tutorial, we will learn how to check the string is empty or not. The &lt;b style=&quot;color: black;&quot;&gt;isEmpty() method&lt;i&gt;&lt;/i&gt;&lt;/b&gt; of the String class is used to check whether the string is empty or not. If the string is empty then the &lt;b style=&quot;color: black;&quot;&gt;isEmpty()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method returns true otherwise it returns false. In other words, we can say that this method returns true if the string length is 0.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Syntax:&lt;/b&gt; The syntax of the isEmpty() of &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;string class&lt;/span&gt;&lt;/a&gt; is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public boolean isEmpty() &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of String isEmpty() method in Java:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;class StringEmpty{
 public static void main(String args[]){
  // Non-empty string.
  String str1 = &quot;Javastudypoint&quot;;
  //empty string.
  String str2 = &quot;&quot;;
  //returns false.
  System.out.println(str1.isEmpty());
  //retuens true.
  System.out.println(str2.isEmpty());
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB1GAejWbIV1vpgtdhWrZF3hfYsp34BPHag3iqjuQLUwmezt-UK61PCHCN3jPjsTs6R0QFan8wWwN-jOTsZJCUwTV5YhnLDYuXV4EwoC3uWy8JUkSlrOA3fv-qEzLdLAsJaZ72BNVQM8UT/s1600/Screenshot+%2528519%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java String isempty() method with Example&quot; border=&quot;0&quot; data-original-height=&quot;536&quot; data-original-width=&quot;557&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB1GAejWbIV1vpgtdhWrZF3hfYsp34BPHag3iqjuQLUwmezt-UK61PCHCN3jPjsTs6R0QFan8wWwN-jOTsZJCUwTV5YhnLDYuXV4EwoC3uWy8JUkSlrOA3fv-qEzLdLAsJaZ72BNVQM8UT/s1600/Screenshot+%2528519%2529.png&quot; title=&quot;Java String isempty() method with Example&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/8714309695985606027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-isempty-method-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8714309695985606027'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/8714309695985606027'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-isempty-method-with-example.html' title='Java String isempty() method with Example'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB1GAejWbIV1vpgtdhWrZF3hfYsp34BPHag3iqjuQLUwmezt-UK61PCHCN3jPjsTs6R0QFan8wWwN-jOTsZJCUwTV5YhnLDYuXV4EwoC3uWy8JUkSlrOA3fv-qEzLdLAsJaZ72BNVQM8UT/s72-c/Screenshot+%2528519%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-2189662436411827448</id><published>2020-01-03T21:24:00.000+05:30</published><updated>2020-01-09T17:50:58.034+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="equalsIgnoreCase() method in java"/><title type='text'>How to compare two Strings using equalsIgnoreCase() Method in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In the last tutorial, We have learned how to compare two strings using &lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-compare-two-strings-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;equals()&lt;/span&gt;&lt;/a&gt; method. But there is one limitation of the equals() method. By default equals() method check the content including &lt;b&gt;&lt;i&gt;case&lt;/i&gt;&lt;/b&gt; also i.e. The comparison is case sensitive. If the comparison is case insensitive it returns false. To overcome this problem we can use the &lt;b&gt;&lt;i&gt;equalsIgnoreCase() method &lt;/i&gt;&lt;/b&gt;in Java. Let&#39;s first see the example of, what the problem to use equals() method.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringCompare{
	public static void main(String args[]){
		String str1 = &quot;Javastudypoint&quot;;
		String str2 = new String(&quot;JAVA&quot;);
		String str3 = new String(&quot;Javastudypoint&quot;);
		String str4 = &quot;Java&quot;;
		System.out.println(str1.equals(str3)); //true
		System.out.println(str2.equals(str4)); //false
		System.out.println(str1.equals(str2)); //false
		
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;true
false
false
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The problem with the above code is it check the case also. In the above code, the &lt;b&gt;&lt;i&gt;str2&lt;/i&gt;&lt;/b&gt; and the &lt;b&gt;&lt;i&gt;str3&lt;/i&gt;&lt;/b&gt; have the same content but the case is different therefore the equals() method returns false.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;equalsIgnoreCase() in Java:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To overcome the above problem, we can use the&lt;b style=&quot;color: black;&quot;&gt;&lt;i&gt; equalsIgnoreCase()&lt;/i&gt;&lt;/b&gt; method. This method is used to perform the comparison that ignores the case differences. When it compares two &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;strings&lt;/span&gt;&lt;/a&gt;, it considered A-Z the same as a-z.&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;Syntax: &lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The syntax of the &lt;b&gt;&lt;i&gt;equalsIgnoreCase()&lt;/i&gt;&lt;/b&gt; is given below:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
public boolean equalsIgnoreCase()&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Comparison of two strings using the method equalsIgnoreCase()&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Let&#39;s understand the &lt;b&gt;&lt;i&gt;equalsIgnoreCase() method in Java&lt;/i&gt;&lt;/b&gt; with an example.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringCompare{
	public static void main(String args[]){
		String str1 = &quot;Javastudypoint&quot;;
		String str2 = &quot;javaSTUDYpoint&quot;;
		String str3 = &quot;JAVASTUDYPOINT&quot;; 
		String str4 = &quot;Java Tutorial&quot;;
               //true because content and case are same
		System.out.println(str1.equalsIgnoreCase(str3));
               //false because content and case are not the same.
		System.out.println(str2.equalsIgnoreCase(str4)); 
               //true because content and case are same
		System.out.println(str1.equalsIgnoreCase(str2)); 
		
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB-Fmesi8r8S7JjYikVsGURcHIx7Pw1Pp8y3e6hLuTJq3pnjsQSjOA6kcAEcO8KbJQbPagbdKt4XA4vDIP97KP501XCoBiRJFKcd4_xi0RFwURqri-orgYW4IrjXyPR_BoA02U0CwlHgiK/s1600/Screenshot+%2528520%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot; compare two Strings using equalsIgnoreCase() Method in Java?&quot; border=&quot;0&quot; data-original-height=&quot;551&quot; data-original-width=&quot;594&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB-Fmesi8r8S7JjYikVsGURcHIx7Pw1Pp8y3e6hLuTJq3pnjsQSjOA6kcAEcO8KbJQbPagbdKt4XA4vDIP97KP501XCoBiRJFKcd4_xi0RFwURqri-orgYW4IrjXyPR_BoA02U0CwlHgiK/s1600/Screenshot+%2528520%2529.png&quot; title=&quot; compare two Strings using equalsIgnoreCase() Method in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/2189662436411827448/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/equalsignorecase-in-java-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/2189662436411827448'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/2189662436411827448'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/equalsignorecase-in-java-string.html' title='How to compare two Strings using equalsIgnoreCase() Method in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB-Fmesi8r8S7JjYikVsGURcHIx7Pw1Pp8y3e6hLuTJq3pnjsQSjOA6kcAEcO8KbJQbPagbdKt4XA4vDIP97KP501XCoBiRJFKcd4_xi0RFwURqri-orgYW4IrjXyPR_BoA02U0CwlHgiK/s72-c/Screenshot+%2528520%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-6005935919926770485</id><published>2020-01-03T19:37:00.000+05:30</published><updated>2020-01-09T18:03:25.737+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java equals() method"/><title type='text'>How to compare two Strings in Java using equals() Method?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The Java &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt; &lt;/a&gt;class provides several methods to compare the content of the two Strings. We can use equals() method to compare the content of the two strings. It returns true, if the content of the two Strings is the same otherwise it returns false. The &lt;b&gt;&lt;i&gt;equals() method&lt;/i&gt;&lt;/b&gt; by default check the content including case also i.e. The comparison is case sensitive. If the comparison is case insensitive it returns false. We can discuss the other way to compare the two strings in our next tutorials. Here, we can discuss only the equals() method.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax: &lt;/b&gt;The syntax of the &lt;b&gt;equals()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method of String class is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
boolean equals(Object obj) &lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, &lt;i&gt;&lt;b&gt;obj&lt;/b&gt;&lt;/i&gt; is the String object being compared with the invoking String object&lt;/span&gt;.
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of compare two Strings by equals() Method&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The simple way to compare the two string is by using the &lt;b&gt;equals()&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method. By default, it checks the content including also case also. Let&#39;s see the example.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringCompare{
	public static void main(String args[]){
		String str1 = &quot;Javastudypoint&quot;;
		String str2 = new String(&quot;Java&quot;);
		String str3 = new String(&quot;Javastudypoint&quot;);
		String str4 = &quot;Java&quot;;
		System.out.println(str1.equals(str3)); //true
		System.out.println(str2.equals(str4)); //true
		System.out.println(str1.equals(str2)); //false
		
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-kjAy_rCpLKAimDxlFdXGPa86EPZPivnFm_YjzJGzneb1m2qtufsUMpJ02aXzCpII9xMJL1x6x3D2-9DBi1IqhnNDL4U_BRDhvnYK8IQqrhotl_p_jOaDU3ST0nKpzpSelN72pQFvsgf0/s1600/Screenshot+%2528521%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;compare two Strings in Java using equals() Method?&quot; border=&quot;0&quot; data-original-height=&quot;551&quot; data-original-width=&quot;589&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-kjAy_rCpLKAimDxlFdXGPa86EPZPivnFm_YjzJGzneb1m2qtufsUMpJ02aXzCpII9xMJL1x6x3D2-9DBi1IqhnNDL4U_BRDhvnYK8IQqrhotl_p_jOaDU3ST0nKpzpSelN72pQFvsgf0/s1600/Screenshot+%2528521%2529.png&quot; title=&quot;compare two Strings in Java using equals() Method?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/6005935919926770485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-compare-two-strings-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/6005935919926770485'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/6005935919926770485'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-compare-two-strings-in-java.html' title='How to compare two Strings in Java using equals() Method?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-kjAy_rCpLKAimDxlFdXGPa86EPZPivnFm_YjzJGzneb1m2qtufsUMpJ02aXzCpII9xMJL1x6x3D2-9DBi1IqhnNDL4U_BRDhvnYK8IQqrhotl_p_jOaDU3ST0nKpzpSelN72pQFvsgf0/s72-c/Screenshot+%2528521%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-4278561654535577865</id><published>2020-01-03T15:01:00.000+05:30</published><updated>2020-01-09T18:23:20.746+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="concat() method in java"/><title type='text'>How to Concatenate two Strings using concat() Method in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;We can &lt;b style=&quot;color: black;&quot;&gt;concatenate two strings in Java&lt;/b&gt; by using concat() method of &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt;&lt;/a&gt; class. It concatenates the specified string to the end of this string. If the length argument of the string is 0 then this string object is returned otherwise a new string object is created.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Syntax:&lt;/b&gt; The syntax of the &lt;b&gt;concat() &lt;/b&gt;method in java is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;public String concat(String str) &lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here &lt;b&gt;str&lt;i&gt;&lt;/i&gt;&lt;/b&gt;, specifies the string to be concatenated at the end of another string.&lt;/span&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;String Concatenate in Java by using concat() Method&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;We can concatenate the two string by using &lt;b&gt;concat()&lt;/b&gt; method. It returns the newly created string &lt;a href=&quot;https://www.javastudypoint.com/2019/05/class-and-object-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;object&lt;/span&gt;&lt;/a&gt;. Let&#39;s see the example.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class charAtExample{
	public static void main(String args[]){
		String str = &quot;Java&quot;;
		String str1 = str.concat(&quot;studypoint&quot;); //concat the string
		System.out.println(&quot;The newly concatenated string is: &quot; +str1);
	    
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM1G8cVs_fJv2PikPxi4ivgPc8pkWK1-3Bcfc3Rlaq03_NqXERGJdTkjCiSkjgtpm3ZxMml2Hsq7X0MGtvAhaYaNolxdeO_jsl0lb9TUfPj-odgWswKDvMkU8YW9gVFRQ_-0hNadLIeOvp/s1600/Screenshot+%2528522%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;How to Concatenate two Strings using concat() Method in Java?&quot; border=&quot;0&quot; data-original-height=&quot;515&quot; data-original-width=&quot;696&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM1G8cVs_fJv2PikPxi4ivgPc8pkWK1-3Bcfc3Rlaq03_NqXERGJdTkjCiSkjgtpm3ZxMml2Hsq7X0MGtvAhaYaNolxdeO_jsl0lb9TUfPj-odgWswKDvMkU8YW9gVFRQ_-0hNadLIeOvp/s1600/Screenshot+%2528522%2529.png&quot; title=&quot;How to Concatenate two Strings using concat() Method in Java?&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/4278561654535577865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-concatenate-two-strings-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/4278561654535577865'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/4278561654535577865'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/how-to-concatenate-two-strings-in-java.html' title='How to Concatenate two Strings using concat() Method in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM1G8cVs_fJv2PikPxi4ivgPc8pkWK1-3Bcfc3Rlaq03_NqXERGJdTkjCiSkjgtpm3ZxMml2Hsq7X0MGtvAhaYaNolxdeO_jsl0lb9TUfPj-odgWswKDvMkU8YW9gVFRQ_-0hNadLIeOvp/s72-c/Screenshot+%2528522%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-1450704117053307094</id><published>2020-01-03T13:06:00.000+05:30</published><updated>2020-01-03T13:06:02.633+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="charAt() method"/><title type='text'>Java String Class charAt() Method with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The &lt;b style=&quot;color: black;&quot;&gt;charAt() method of String class&lt;/b&gt; is used to return the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for &lt;a href=&quot;https://www.javastudypoint.com/2019/12/array-in-java-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;array&lt;/span&gt;&lt;/a&gt; indexing. If the specified index is not there then you will get StringIndexOutOfBoundExceptions: string index out of range.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Syntax:&lt;/b&gt; The syntax of the &lt;a href=&quot;https://www.javastudypoint.com/2020/01/string-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;String&lt;/span&gt;&lt;/a&gt; class charAt() method is given below.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public char charAt(int index) &lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here, the index is the index of the character that you want to obtain. The charAt() method returns the character at the specified position.&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:inline-block;width:336px;height:280px&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;9992676996&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Java String Class charAt() method Example.&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Let&#39;s understand the String charAt() method with an example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class charAtExample{
	public static void main(String args[]){
		String str = &quot;Javastudypoint&quot;;
	    char ch = str.charAt(7); //returns the char value at 7th index.
	    System.out.println(&quot;The value at 7th index is: &quot; +ch);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;
Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt; &lt;/span&gt;The value at 7th index is: d &lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; font-size: xx-large; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;StringIndexOutOfBoundsException with charAt() Method.&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The charAt() method of String class throws &lt;b&gt;&lt;i&gt;StringIndexOutOfBoundsException&lt;/i&gt;&lt;/b&gt; if the specified index argument is negative or the greater of the length of the string. Let&#39;s see the example.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;Case 1: &lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;When the index argument is greater than the length of the string.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
class charAtExample{
	public static void main(String args[]){
		String str = &quot;Javastudypoint&quot;;
	    char ch = str.charAt(20); //StringIndexOutOfBoundsException
	    System.out.println(&quot;The value at 7th index is: &quot; +ch);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-size: x-large;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-size: xx-large; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc8ZYoGE5hcP6ZRLM-LzsNWNJeXbYsDncEnQalUtzWhYeWjCiGvrs_HJ6qxIvdxFvqKM6EjWvETrvmjdURd7tRWiFJiTHu6hQ2cQ3Fr0NsZPZ2TBGBnBRt5JurBBzLDLnylTnQgSLdFLMH/s1600/Screenshot+%2528493%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java String Class charAt() method&quot; border=&quot;0&quot; data-original-height=&quot;297&quot; data-original-width=&quot;1099&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc8ZYoGE5hcP6ZRLM-LzsNWNJeXbYsDncEnQalUtzWhYeWjCiGvrs_HJ6qxIvdxFvqKM6EjWvETrvmjdURd7tRWiFJiTHu6hQ2cQ3Fr0NsZPZ2TBGBnBRt5JurBBzLDLnylTnQgSLdFLMH/s1600/Screenshot+%2528493%2529.png&quot; title=&quot;StringIndexOutOfBoundsException with charAt() method&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;Case 2:&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; When the index argument is negative. Let&#39;s see the example.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class charAtExample{
	public static void main(String args[]){
		String str = &quot;Javastudypoint&quot;;
	    char ch = str.charAt(-10); //StringIndexOutOfBoundsException
	    System.out.println(&quot;The value at -10th index is: &quot; +ch);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: verdana, sans-serif; font-size: xx-large; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5DL6CzRtfyf2nW2JjSmdO_8e2lylmQc_OyCHHl8Ojv9WP2Id95hjIBUVLwzh3zpx4jAyLZuhzjtKTTUZUQM41gFmONuggIln3-eQq5cQD5knOkI63zLAAKz56dKDXgXJT2jKnT-JY_5Gl/s1600/Screenshot+%2528494%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Java string class charAt() method&quot; border=&quot;0&quot; data-original-height=&quot;310&quot; data-original-width=&quot;1109&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5DL6CzRtfyf2nW2JjSmdO_8e2lylmQc_OyCHHl8Ojv9WP2Id95hjIBUVLwzh3zpx4jAyLZuhzjtKTTUZUQM41gFmONuggIln3-eQq5cQD5knOkI63zLAAKz56dKDXgXJT2jKnT-JY_5Gl/s1600/Screenshot+%2528494%2529.png&quot; title=&quot;StringIndexOutOfBoundsException with charAt() method&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/1450704117053307094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-class-charat-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1450704117053307094'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/1450704117053307094'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/java-string-class-charat-method.html' title='Java String Class charAt() Method with Example'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc8ZYoGE5hcP6ZRLM-LzsNWNJeXbYsDncEnQalUtzWhYeWjCiGvrs_HJ6qxIvdxFvqKM6EjWvETrvmjdURd7tRWiFJiTHu6hQ2cQ3Fr0NsZPZ2TBGBnBRt5JurBBzLDLnylTnQgSLdFLMH/s72-c/Screenshot+%2528493%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-3836208008648003100</id><published>2020-01-03T00:49:00.001+05:30</published><updated>2020-01-25T16:40:21.348+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java String Class"/><title type='text'>String Class in Java | Why String is Immutable in Java?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In Java, a string is a sequence of characters. But, unlike many other languages that implement strings as character arrays, Java implements strings as objects of type string. &lt;b&gt;String class in Java&lt;/b&gt; is defined in the java.lang &lt;a href=&quot;https://www.javastudypoint.com/2019/12/packages-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;package&lt;/span&gt;&lt;/a&gt;. Thus, this class available to all the programs automatically. When you create a String Class object, you are creating a string that cannot be changed. Hence, the objects of the String class are immutable.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;What is String immutability?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;String objects in &lt;span style=&quot;color: lime;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/01/what-is-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;Java&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;are immutable that means you cannot change the content of a string once they created. Let&#39;s understand the concept of string immutability with an example. In this example, we created a string object with the help of a new keyword that contains the string &lt;b&gt;&quot;Java&quot;&lt;/b&gt; and in the next statement, we want to concat this string with other string&lt;b&gt; &quot;Tutorial&quot;&lt;/b&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;But when we concat the string a new object will be created in the existing object, and we can&#39;t able to perform any changes. When we concat &lt;b&gt;&quot;Java&quot;&lt;/b&gt; with &lt;b&gt;&quot;Tutorial&quot;&lt;/b&gt; it will become Java Tutorial. But this new object is not assigning with any reference variable then automatically this object eligible for the garbage collector. That&#39;s why we will get only &quot;Java&quot; as an output. See the image given below:&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirlC3PfJHgoap6svBTkCCMRlnMESMhgrF8vVaE7uqOHJyMbdpY5KBkzJMGsuUeNOdOfwDw-oW2KFeXuCf596yjVU_cvVqM1imzefKinXT2ybVv0FmjR1sjLx272J6m0-RA5qoXsO2GfILM/s1600/Screenshot+%2528492%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;String class in java&quot; border=&quot;0&quot; data-original-height=&quot;281&quot; data-original-width=&quot;538&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirlC3PfJHgoap6svBTkCCMRlnMESMhgrF8vVaE7uqOHJyMbdpY5KBkzJMGsuUeNOdOfwDw-oW2KFeXuCf596yjVU_cvVqM1imzefKinXT2ybVv0FmjR1sjLx272J6m0-RA5qoXsO2GfILM/s1600/Screenshot+%2528492%2529.png&quot; title=&quot;String class in java&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class StringExample{
	public static void main(String args[]){
		String str = new String(&quot;Java&quot;);
	    str.concat(&quot;Tutorial&quot;);
	    System.out.println(str);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Java &lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; font-size: x-large; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;How to create a string object in Java?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;We can create a string object in java by using two ways:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;1. By using String literals.&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. By using the new Keyword.&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;1. By using String literals: &lt;/b&gt;We can create a string &lt;a href=&quot;https://www.javastudypoint.com/2019/05/class-and-object-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;object&lt;/span&gt;&lt;/a&gt; by using string literals. In String literals, we can create a string by using double-quotes. For example:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
String str = &quot;Javastudypoint&quot;;
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;Each time when you create a String by using String literal, the JVM first checks whether the object is present in the string pool or not. If it is already present then the same reference is returned otherwise a new object will be created in the string pool and then return the reference.&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. By using the new keyword:&amp;nbsp;&lt;/b&gt;When we create a String using the new keyword, the JVM creates a new String object in heap memory and the String literal &lt;b&gt;&quot;Javastudypoint&quot;&lt;i&gt;&lt;/i&gt;&lt;/b&gt; will be placed inside the String pool and the variable str will refer to the String object in heap.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
String str = new String(&quot;Javastudypoint&quot;);
&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Advantage of String Constant Pool:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;The biggest advantage of String constant pool is the same object can be reused multiple times instead of creating new objects. Therefore memory will be saved and performance will be improved.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Disadvantage of String Constant Pool:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;As we know, because of the string constant pool one object can be reused by multiple references. If one reference any person can try to change then all the remaining references can be affected this is the biggest disadvantage of String Constant Pool.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Why String class objects are immutable?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The meaning of the immutable string is once we create a string its value cannot be changed.&amp;nbsp;The String is immutable in nature because it uses the concept of String literals.&amp;nbsp;Let&#39;s take an example to understand this:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: black;&quot;&gt;String str1 = &quot;Java&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: black;&quot;&gt;String str2 = &quot;Java&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In this example, the two reference variables refer to the same object. if one reference variable changes the value of the object(suppose &quot;java&quot; to &quot;python&quot;), It will affect to all the reference variable. That&#39;s why the String object is immutable in nature.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java String class constructors:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The String class in java supports several &lt;a href=&quot;https://www.javastudypoint.com/2018/12/constructor-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;constructors&lt;/span&gt;&lt;/a&gt;. The most commonly used constructors are given below:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;1. String():&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Initializes a newly created String object so that it represents an empty character sequence. For example:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt; String str = new String(); &lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;2. String(char chars[]):&lt;/b&gt; This constructor can be used to create a string initialized by an &lt;a href=&quot;https://www.javastudypoint.com/2019/12/array-in-java-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;array&lt;/span&gt; &lt;/a&gt;of characters. For example.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
char chars[] = {&#39;a&#39;, &#39;b&#39;, &#39;c&#39;};
String str = new String(chars);  //abc
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;3. String(char chars[], int startIndex, int numChars):&lt;/b&gt; This constructor can be used to specify a subrange of a character array as an initializer. Here, startIndex specifies the index at which the subrange begins, and numChars specifies the number of characters to use. For example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
char chars[] = {&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;};
String str = new String(chars, 2, 3);  //cde.
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;4. String(String strObj):&lt;/b&gt; We can use this constructor to construct a String object that contains the same character sequence as another string object. Here, stringObj is a string object. For example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
char ch[] = {&#39;J&#39;, &#39;a&#39;, &#39;v&#39;, &#39;a&#39;};
String str1 = new String(ch);  //Java.
String str2 = new String(str1); //Java.
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;5. String(byte[] b ):&lt;/b&gt; This constructor is used to create a new string object by decoding the byte array. These byte values are converted into corresponding characters. For example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
byte[] b = {97, 98, 99, 100);
String str = new String(b);
System.out.println(str); //abcd
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;6. String(StringBuffer buffer):&lt;/b&gt; This constructor is used to create a new string that contains the sequence of characters currently contained in the StringBuffer argument. For example.&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
StringBuffer buffer = new StringBuffer(&quot;Javastudypoint&quot;);
String str = new String(buffer); // Javastudypoint
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;7. String(StringBuilder builder):&lt;/b&gt; This constructor is used to create a new string that contains the sequence of characters currently contained in the StringBuilder argument. For example.&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
StringBuilder builder = new StringBuilder(&quot;Javastudypoint&quot;);
String str = new String(builder); // Javastudypoint
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block; font-family: verdana, sans-serif;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;String class Methods in Java&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The String Class in Java provides many methods. The most commonly used methods are given below. We can discuss each method in detail in our next tutorials. Here, we can only introduce these methods.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-class-charat-method.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;1. char charAt(int index):&lt;/span&gt;&lt;/a&gt;&lt;/b&gt; This method is used to return the char value at the specified index. If the specified index is not there then you will get StringIndexOutOfBoundExceptions: string index out of range.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-concatenate-two-strings-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;2. String concat(String str):&lt;/span&gt;&lt;/a&gt;&lt;/b&gt; This method is used to concatenates the specified string to the end of this string.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-compare-two-strings-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;3. boolean equals(Object obj):&lt;/span&gt;&lt;/a&gt; &lt;/b&gt;This method is used for content comparison. It is the overriding method of the object class. The equals() method by default check content including case also i.e. The comparison is case sensitive. If the comparison is case insensitive then this method returns false.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/equalsignorecase-in-java-string.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;4. boolean equalsIgnoreCase(String str):&lt;/span&gt;&lt;/a&gt;&lt;/b&gt; This method is used to perform the comparison that ignores the case differences. When it compares two strings, it considered A-Z to the same as a-z.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-isempty-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;5. boolean isEmpty():&lt;/span&gt;&lt;/a&gt;&lt;/b&gt; This method is used to check whether the string is empty or not. If the string is empty, it returns true else it returns false.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-find-string-length-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;6. int length():&lt;/span&gt;&lt;/a&gt;&lt;/b&gt; This method is used to returns the number of characters in the string. Remember that the length variable is used for array and the length() method is used for String. If you can use the length variable to find the length of the string then the compiler will get a compile-time error.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-replace-string-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;7. String replace(char oldChar, char newChar):&lt;/span&gt;&lt;/a&gt; &lt;/b&gt;This method is used to replacing all the occurrences of the oldChar in this string with newChar.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-find-substring-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;8. String substring(int startIndex):&lt;/span&gt;&lt;/a&gt;&lt;/b&gt; This method returns the string from the beginning index to the end of the string. Here, startIndex specifies the index at which the substring will begin.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: lime; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-substring-method.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;9. String substring(int startIndex, int endString):&lt;/a&gt;&lt;/b&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns String from the beginning index, up to, but not including, the ending index.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: lime;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-indexof-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;10. int indexOf(int ch):&lt;/a&gt;&lt;/b&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the index of the first occurrence of the specified character. If the specified character is not present there then it returns -1.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-lastindexof-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/a&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-lastindexof-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;11. int lastIndexOf(int ch):&lt;/a&gt; &lt;/b&gt;This method returns the index of the last occurrence of the specified character.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;12. int indexOf(int ch, int fromIndex):&lt;/b&gt; &lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the index of the first occurrence of the specified character, starting the search from the specified index.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black; font-family: verdana, sans-serif;&quot;&gt;13. int lastIndexOf(int ch, int fromIndex): &lt;/b&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the index of the last occurrence of the specified character, starting the search from the backward specified index.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;14. int indexOf(String str):&lt;/b&gt; &lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the index of the first occurrence of the specified substring.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;15. int lastIndexOf(String str):&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; This method returns the index of the last occurrence of the specified substring.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b style=&quot;color: black; font-family: verdana, sans-serif;&quot;&gt;16. int indexOf(String str, int fromIndex):&lt;/b&gt; &lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the index of the first occurrence of the specified substring, starting the search from the specified index.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;17. int lastIndexOf(String str, int fromIndex):&lt;/b&gt; &lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the index of the last occurrence of the specified substring, starting the search from the backward specified index.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: lime;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-into-lowercase-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;18. String toLowerCase():&lt;/a&gt;&lt;/b&gt; &lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method converts all the characters in a string from uppercase to the lowercase.&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-uppercase-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;19. String toUpperCase():&lt;/a&gt;&lt;/b&gt; &lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method converts all the characters in a string from lowercase to the uppercase.&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-trim-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/a&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/java-string-trim-method-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;20. String trim():&lt;/a&gt; &lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method returns the copy of the string by removing whitespaces at both ends. It doesn&#39;t remove the whitespaces in the middle.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/how-to-convert-a-string-to-char-array-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;21. char[] toCharArray():&lt;/a&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; This method is used to convert a string into a char array.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2020/01/compare-two-strings-lexicographically-in-java.html&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;22. int compareTo(String str):&lt;/a&gt;&lt;/b&gt; &lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This method is used to compare the two strings lexicographically. It returns a positive number, negative number or 0.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/3836208008648003100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2020/01/string-class-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/3836208008648003100'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/3836208008648003100'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2020/01/string-class-in-java.html' title='String Class in Java | Why String is Immutable in Java?'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirlC3PfJHgoap6svBTkCCMRlnMESMhgrF8vVaE7uqOHJyMbdpY5KBkzJMGsuUeNOdOfwDw-oW2KFeXuCf596yjVU_cvVqM1imzefKinXT2ybVv0FmjR1sjLx272J6m0-RA5qoXsO2GfILM/s72-c/Screenshot+%2528492%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-3813472358259057455</id><published>2019-12-28T15:39:00.000+05:30</published><updated>2019-12-28T15:39:56.160+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="array in java"/><title type='text'>Array in Java with Example | How to Initialize Array in java </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Array in Java &lt;/b&gt;is an object that holds multiple values in a single variable. The array can hold the value of only a similar data type. If you want to represent the huge number of values by using a single &lt;a href=&quot;https://www.javastudypoint.com/2019/12/types-of-variables-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;variable &lt;/span&gt;&lt;/a&gt;then you can go for &lt;b style=&quot;color: black;&quot;&gt;Array&lt;/b&gt;. We can create an array of any type and may have one or more dimensions. The length of an array is established when an array is created. After creation, the length of the array is fixed. &lt;b style=&quot;color: black;&quot;&gt;Array in Java&lt;/b&gt; is based on the index. Each item in an array called an element, and each element is accessed by its index number. The index number begins with 0 and the 9th element, for example, would, therefore, be accessed at index 8.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeaxkV2X8mU1IteDHGyb_gOHK53DfgZaH4XxqEftVBVCLbY1a7Omtn553LFbomawIw6UR3_PIdA3Umsn0SLjgk8F7gBCCA6T-gb0ooM0hEJD5qv4HZxPqjq2D83HfK3bOJXxHuPGCuCPnd/s1600/Screenshot+%2528491%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Array in java with example&quot; border=&quot;0&quot; data-original-height=&quot;202&quot; data-original-width=&quot;591&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeaxkV2X8mU1IteDHGyb_gOHK53DfgZaH4XxqEftVBVCLbY1a7Omtn553LFbomawIw6UR3_PIdA3Umsn0SLjgk8F7gBCCA6T-gb0ooM0hEJD5qv4HZxPqjq2D83HfK3bOJXxHuPGCuCPnd/s1600/Screenshot+%2528491%2529.png&quot; title=&quot;Array in java with example&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Advantages of Array:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. We can represent a huge number of values by using a single variable.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. We can easily search any element of an array by using the index number.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Disadvantages of Array:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. Arrays are fixed in size.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The length of an array is established when an array is created. Once we create an array with some size then there is no chance of increasing or decreasing the size of an array based on our requirements.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. Arrays can hold only homogenous &lt;a href=&quot;https://www.javastudypoint.com/2019/12/basic-data-types-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;data type&lt;/span&gt;&lt;/a&gt; of elements.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Note:&lt;/b&gt; To overcome the limitation of an array we should go for &lt;a href=&quot;https://www.javastudypoint.com/2019/02/collection-framework-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;collection&lt;/span&gt;&lt;/a&gt; in Java.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Types of Array in java:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;There are two types of &lt;b&gt;Array in Java&lt;/b&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. One-dimensional Array.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. Multidimensional Array.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to declare Array in Java?&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;We can declare an array by using different ways. The general form of a one-dimensional array declaration is:&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;code&gt;
data-type[] variable-name; Or
data-type []variable-name; Or
data-type variable-name[];
&lt;/code&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;All the above-mentioned declaration is valid. You can use any one of the above declarations. Here &lt;b&gt;&lt;i&gt;data-type &lt;/i&gt;&lt;/b&gt;describe the what type of data the array will hold and &lt;b&gt;&lt;i&gt;variable-name&lt;/i&gt;&lt;/b&gt; describe the reference of the array.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to instantiate an Array in Java?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Once an array is declared, the only reference of an array is created. But you need to use it now to allocate memory for arrays. We can use the &lt;b&gt;&lt;i&gt;new&lt;/i&gt;&lt;/b&gt; keyword to instantiate an array. The general form of instantiating an array appears as follows:&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
variable-name = new data-type[size];
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here &lt;b&gt;&lt;i&gt;data-type&lt;/i&gt;&lt;/b&gt; specifies the type of data being allocated, &lt;b&gt;&lt;i&gt;size &lt;/i&gt;&lt;/b&gt;specifies the number of elements in the array, and &lt;b&gt;&lt;i&gt;variable-name&lt;/i&gt;&lt;/b&gt; specifies the reference of an array that is referred to the array.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to initialize an array in Java?&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Arrays can be initialized &lt;/b&gt;when they declared or later in the program as per your requirements. We can initialize the array by a list of comma-separated expressions surrounded by curly braces. The commas separate the value of the array elements. The general form of one-dimensional array initialization is as follows:&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
int array[] = {10, 20, 40, 50}; OR
arrayRefvarName[index-number] = value;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Array in Java&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Let&#39;s understand the concept of an&lt;b&gt; array&lt;i&gt;&lt;/i&gt;&lt;/b&gt; with an example. In this example, we create an array of int type, we initialize the array and traverse the array to print the values of array.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
class ArrayExample{
	public static void main(String args[]){
		//Array declaration.
		int[] array;
		
		// Array instantiate.
		array = new int[5];
		
		//Array initialization.
		array[0] = 10;
		array[1] = 20;
		array[2] = 30;
		array[3] = 40;
		array[4] = 50;
		
		//traverse the array.
		for(int i = 0; i&amp;lt;array.length;i++){
			System.out.println(&quot;Element at index &quot; +i+ &quot; is: &quot; +array[i]);
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
Element at index 0 is: 10
Element at index 1 is: 20
Element at index 2 is: 30
Element at index 3 is: 40
Element at index 4 is: 50
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Multidimensional Array in Java:&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Multidimensional Arrays in Java&lt;/b&gt; are actually arrays of arrays. The elements of a multidimensional array are stored in the form of row and column also known as matrix form
&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;How to declare a Multidimensional Array in Java?&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The general form of declaration of Multidimensional Array is as follow:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
data-type[][] arrayRefVarName; (OR)
data-type arrayRefVaName[][];  (OR)
data-type [][]arrayRefVarName;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;How to instantiate a Multidimensional Array?&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Once an array is declared, the only reference of an array is created. But you need to use it now to allocate memory for arrays. The general form of instantiating a Multidimensional array appears as follows:&lt;/span&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
int[][] array = new int[2][2] //2 row &amp;amp; 2 column
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;How to initialize a Multidimensional array in Java?&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Multidimensional Arrays can be initialized when they declared or later in the program as per your requirements. The general form of multidimensional array initialization is as follows:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
int[][] array = {{1,2,3}, {4,5,6}, {7,8,9}};
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;h2&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of Multidimensional Array in Java:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Let&#39;s see a simple example to understand the Multidimensional array. In this example, we declare and initialize the multidimensional array and we can also print the value of this array in the form to row and column.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class ArrayExample{
	public static void main(String args[]){
		
		//Declaration and initialization.
		// of 2-D array
		int[][] array = {{1,2,3}, {4,5,6}, {7,8,9}};
		
		//loop for row and column.
		for(int i=0; i&amp;lt;3; i++){
			for(int j=0;j&amp;lt;3;j++){
				//print the elements of 2-D array.
				System.out.print(array[i][j] + &quot; &quot;);
			}
			System.out.println();
		}
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt; Output:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
1 2 3
4 5 6
7 8 9
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;How to copy data from one array to another?&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The System class has an &lt;b&gt;arraycopy&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method that you can use to efficiently copy data from one array into another. The syntax is given below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
public static void arraycopy(Object src, int srcPos,
                             Object dest, int destPos, int length);
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The two Object arguments specify the array to &lt;b&gt;copy from&lt;i&gt;&lt;/i&gt;&lt;/b&gt; and the array to &lt;b&gt;copy to&lt;i&gt;&lt;/i&gt;&lt;/b&gt;. The three int arguments specify the starting position in the source array, the starting position in the destination array, and the number of array elements to copy.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of copying an array in java:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In this example, we can declare an array of char elements. It uses the &lt;b&gt;System.arraycopy&lt;i&gt;&lt;/i&gt;&lt;/b&gt; method to copy a subsequence of array component into the second array. Let&#39;s see the example.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
class ArrayCopy{
    public static void main(String[] args){
		
		//declaring a source array.
        char[] copyFrom = { &#39;d&#39;, &#39;e&#39;, &#39;j&#39;, &#39;a&#39;, &#39;v&#39;, &#39;a&#39;, &#39;s&#39;,
			    &#39;t&#39;, &#39;u&#39;, &#39;d&#39;, &#39;y&#39;, &#39;p&#39;, &#39;o&#39;,&#39;i&#39;,&#39;n&#39;,&#39;t&#39;};
				
		 //declaring a destination array.		
        char[] copyTo = new char[14];
		
         //copying an array using arraycopy method.
        System.arraycopy(copyFrom, 2, copyTo, 0, 14);
		
		 //printing the destination array.
        System.out.println(new String(copyTo));
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
javastudypoint
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;You may also like these posts:
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/interface-in-java-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;1. Interface in Java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/access-modifiers-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;2. Access Modifiers - Private, Default, Protected, Public&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/packages-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;3. Packages in Java with Example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/super-keyword-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;4. What is the use of a super keyword in java?&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-this-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;5. What is the need for this keyword in Java?&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-final-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;6. Final Keyword - Final Class, Final Variable and Method.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-oops-concepts.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;7. Java OOPs Concepts complete tutorial.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-control-statements.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;8. Java Control statements with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/operators-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;9. Types of operators in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/05/core-java-interview-questions.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;10. Top 100 java interview question and answer.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/3813472358259057455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2019/12/array-in-java-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/3813472358259057455'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/3813472358259057455'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2019/12/array-in-java-with-example.html' title='Array in Java with Example | How to Initialize Array in java '/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeaxkV2X8mU1IteDHGyb_gOHK53DfgZaH4XxqEftVBVCLbY1a7Omtn553LFbomawIw6UR3_PIdA3Umsn0SLjgk8F7gBCCA6T-gb0ooM0hEJD5qv4HZxPqjq2D83HfK3bOJXxHuPGCuCPnd/s72-c/Screenshot+%2528491%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-3042186284828366853</id><published>2019-12-27T10:57:00.000+05:30</published><updated>2019-12-27T11:29:34.570+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java Interface"/><title type='text'>Interface in Java with Example - Multiple Inheritance using Interface</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;An &lt;b style=&quot;color: black;&quot;&gt;interface in java&lt;/b&gt; is syntactically similar to classes, but they do not have instance variable and their method are declared without any body. The methods declared inside an interface&lt;b style=&quot;color: black;&quot;&gt; &lt;/b&gt;are by default abstract(only method signature, not implementation) and the &lt;a href=&quot;https://www.javastudypoint.com/2019/12/types-of-variables-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;variables&lt;/span&gt; &lt;/a&gt;declared inside an interface are public, static, and final by default. The &lt;b style=&quot;color: black;&quot;&gt;interface in java&lt;/b&gt; is a mechanism to achieve abstraction. Once an interface is defined, any number of classes can implement this interface. Also, one class can implement any number of interfaces.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Why interface in java is used.&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. An &lt;b style=&quot;color: black;&quot;&gt;interface in Java&lt;/b&gt; can be used to achieve total &lt;a href=&quot;https://www.javastudypoint.com/2018/12/abstract-class-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;abstraction&lt;/span&gt;&lt;/a&gt;(100 % abstraction).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. As we know, Java does not support multiple inheritance in the case of class but using the interface we can achieve multiple inheritance in java.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;3. It can also be used to achieve loose coupling.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsv8uod9SUMorcO-T4f8Y8ZqnK0dAK9jvyji1No66Q7Jth9NTJzxiCDv9zViK26xgn9KL4M5-WZ_GZPecY4gbin7pHGQD3XJevI8AFy4tkvaOP_379Ll1thfFhAwIL2nfuOuTa62qWA9ed/s1600/Screenshot+%2528490%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;interface in java&quot; border=&quot;0&quot; data-original-height=&quot;425&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsv8uod9SUMorcO-T4f8Y8ZqnK0dAK9jvyji1No66Q7Jth9NTJzxiCDv9zViK26xgn9KL4M5-WZ_GZPecY4gbin7pHGQD3XJevI8AFy4tkvaOP_379Ll1thfFhAwIL2nfuOuTa62qWA9ed/s1600/Screenshot+%2528490%2529.png&quot; title=&quot;why interface in java is used	&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to define an Interface.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;An &lt;b style=&quot;color: black;&quot;&gt;Interface&lt;/b&gt; is defined much like a &lt;a href=&quot;https://www.javastudypoint.com/2019/05/class-and-object-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;class&lt;/span&gt;&lt;/a&gt;. It can have methods and variables like class. But in Interface, all the methods are by default &lt;b style=&quot;color: black;&quot;&gt;abstract&lt;/b&gt; and all the variables are by default public static, and final. This is the general form of an interface:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
interface name{
  return-type method-name1(parameter-list);
  return-type method-name2(parameter-list);
  type varname1 = value;
  type varname2 = value;
  //.....
  return-type method-nameN(parameter-list);
  type varnameN = value;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;h3 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;How to implement an Interface.&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Once an &lt;b&gt;interface&lt;/b&gt; has been defined, one or more classes can implement that interface. To implement an interface, include the implements clause in a class definition, and create the methods defined by the interface. The general form of a class that includes the implements clauses look like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
class classname implements interface-name{
    // class body
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To &lt;b&gt;implement&lt;/b&gt; an interface, a class must create a complete set of methods defined by the interface. However, each class is free to determine the details of its own implementation. If a class implements more than one interface, then the interfaces are separated with a comma.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of Interface in Java:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Let&#39;s understand the &lt;b&gt;interface&lt;/b&gt; with the help of a real-world example of banks like PNB, SBI, OBC, etc. they have common functionality such as &lt;b&gt;rate of interest&lt;/b&gt;. So we can make an interface and put all the common functionality inside this interface, and lets PNB, SBI, and OBC, etc implement these functionalities in their own class in their own way.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
interface Bank{
	float rateOfInterest();
}
class PNB implements Bank{
	public float rateOfInterest(){
		return 9.5f;
	}
}
class SBI implements Bank{
	public float rateOfInterest(){
		return 8.5f;
	}
}
class OBC implements Bank{
	public float rateOfInterest(){
		return 7.5f;
	}
}
class InterfaceExample{
	public static void main(String args[]){
		Bank b = new PNB();
		System.out.println(&quot;Rate of interest of PNB is: &quot; +b.rateOfInterest());
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;Rate of interest of PNB is: 9.5&lt;span style=&quot;font-size: x-large;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; font-size: xx-large; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Multiple Inheritance by using the interface in java:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;div style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;As we know, we cannot achieve &lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2018/12/inheritance-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;multiple inheritance&lt;/span&gt;&lt;/a&gt; &lt;/b&gt;in the case of class because of the ambiguity problem.&amp;nbsp;but using the interface we can achieve multiple inheritance in java. Let&#39;s see the example.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async=&quot;&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;br /&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-slot=&quot;9992676996&quot; style=&quot;display: inline-block; height: 280px; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-size: xx-large; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Java program for multiple inheritance using interface:&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
interface InterfaceOne{
	public void display();
}
interface InterfaceTwo{
	public void display();
}
class Main implements InterfaceOne,InterfaceTwo{
	public void display(){
		System.out.println(&quot;Display() method implementation&quot;);
	}
	public static void main(String args[]){
		Main obj = new Main();
		obj.display();
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-size: x-large;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;Display() method implementation&lt;span style=&quot;font-size: x-large;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; font-size: xx-large; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Interface and Inheritance:
&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;As we know, A class can implement an interface but an interface cannot implement another interface. One &lt;b&gt;interface&lt;/b&gt; can extend another interface. One interface can extend another interface by use of &lt;b&gt;extends &lt;/b&gt;keyword. The syntax is the same as for inheriting the classes. When a class implements an interface that inherits another interface, it must provide the implementation for all methods defined within the interface. Let&#39;s see the example:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
interface InterfaceOne{
	public void display();
}
interface InterfaceTwo extends InterfaceOne{
	public void show();
}
class Main implements InterfaceTwo{
	public void display(){
		System.out.println(&quot;Display() method implementation.&quot;);
	}
	public void show(){
		System.out.println(&quot;Show() method implementation.&quot;);
	}
	public static void main(String args[]){
		Main obj = new Main();
		obj.display();
		obj.show();
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-size: x-large;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
Display() method implementation.
Show() method implementation.
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: verdana, sans-serif; font-size: xx-large;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;You may also like these posts:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;1&lt;a href=&quot;https://www.javastudypoint.com/2019/12/access-modifiers-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;. Access Modifiers in Java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/packages-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;2. Packages in Java with example.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-final-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;3. Final Class, Final Variable, Final Method in Java.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/super-keyword-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;4. What is the use of a super keyword in Java?&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-this-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;5. What is the need for this keyword in Java?&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-oops-concepts.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;6. Java OOPs Concepts with example.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/operators-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;7. Types of operators in java with example.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-control-statements.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;8. Java Control statement with example.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/02/collection-framework-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;9. Java Collection framework complete tutorial.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/05/core-java-interview-questions.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime; font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;10. Top 100 Java interview question and answer.&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;



&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/3042186284828366853/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2019/12/interface-in-java-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/3042186284828366853'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/3042186284828366853'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2019/12/interface-in-java-with-example.html' title='Interface in Java with Example - Multiple Inheritance using Interface'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsv8uod9SUMorcO-T4f8Y8ZqnK0dAK9jvyji1No66Q7Jth9NTJzxiCDv9zViK26xgn9KL4M5-WZ_GZPecY4gbin7pHGQD3XJevI8AFy4tkvaOP_379Ll1thfFhAwIL2nfuOuTa62qWA9ed/s72-c/Screenshot+%2528490%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-9084036697995820807</id><published>2019-12-26T17:53:00.002+05:30</published><updated>2019-12-26T17:58:35.410+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java Access Modifiers"/><title type='text'>Access Modifiers in Java - Private, Default, Protected, Public Modifiers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;Access Modifiers in Java&lt;/b&gt; are used to restricts access of a class, &lt;a href=&quot;https://www.javastudypoint.com/2018/12/constructor-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;constructor&lt;/span&gt;&lt;/a&gt;, data member, and method in another class. There are four types of access modifiers available in &lt;a href=&quot;https://www.javastudypoint.com/2019/01/what-is-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;Java&lt;/span&gt;&lt;/a&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. Private Access Modifier.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2.Default Access Modifier.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;3. Protected Access Modifier.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;4. Public Access Modifier.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Access Modifiers Table:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt; &lt;span style=&quot;color: black;&quot;&gt;Let&#39;s understand &lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;Java access modifiers &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: black;&quot;&gt;with the help of the table.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP43T56hcrggARTob9_x5JPlhaGtJfF4FVQB3R0Ix7J67gA3nfN4xXdF199_yItyk-lfSLL5yMJhPTu4HLQMiKOngVceqBVLQ7VukWHop3HmfwN4ozox6Wj8Eim8En5iLtd0AKJH1l0zgf/s1600/Screenshot+%2528489%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Access Modifiers in java&quot; border=&quot;0&quot; data-original-height=&quot;353&quot; data-original-width=&quot;655&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP43T56hcrggARTob9_x5JPlhaGtJfF4FVQB3R0Ix7J67gA3nfN4xXdF199_yItyk-lfSLL5yMJhPTu4HLQMiKOngVceqBVLQ7VukWHop3HmfwN4ozox6Wj8Eim8En5iLtd0AKJH1l0zgf/s1600/Screenshot+%2528489%2529.png&quot; title=&quot;Access Modifiers in java - public, private, default, protected&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 style=&quot;color: black; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;1. Private Access Modifier:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The &lt;b style=&quot;color: black;&quot;&gt;private access modifier&lt;/b&gt; is only accessible within the same &lt;a href=&quot;https://www.javastudypoint.com/2019/05/class-and-object-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;class&lt;/span&gt;&lt;/a&gt; in which they are declared. The data member and method declared as private cannot be accessed from outside the class. If you try to access the private data member and method from outside the class then the compiler will give you a compile-time error.&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;fluid&quot; data-ad-layout=&quot;in-article&quot; data-ad-slot=&quot;5403717144&quot; style=&quot;display: block; text-align: center;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;color: black; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of Private Access Modifier:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;class PrivateModifier{
	private int num = 10;
	private void display(){
		System.out.println(&quot;Value of num is: &quot; +num);
	}
}
class AccessModifiers{
	public static void main(String args[]){
		PrivateModifiers obj = new PrivateModifiers();
		System.out.println(obj.num);
		obj.display();
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
Compile time error:
error: num has private access in PrivateModifier(class)
          System.out.println(obj.num);
error: display() has private access in PrivateModifier(class)
          obj.display();
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;color: black; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;
2. Default Access Modifier:
&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The class, data member, and method that are not declared using any modifier, it treated as &lt;b style=&quot;color: black;&quot;&gt;default access modifier&lt;/b&gt; by default. The default access modifier will be accessible within the same &lt;a href=&quot;https://www.javastudypoint.com/2019/12/packages-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;package&lt;/span&gt;&lt;/a&gt;. If you try to access the default modifier from outside the package then the compiler will give you a compile-time error.&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h3 style=&quot;color: black; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Default Access Modifier:&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In this example, we will create two packages &lt;b&gt;&lt;i&gt;pack1&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;pack2&lt;/i&gt;&lt;/b&gt; and the classes inside the packages are default access modifier&amp;nbsp;and we accessing the &lt;b&gt;&lt;i&gt;class A&lt;/i&gt;&lt;/b&gt; from outside the package. Since class A is not public therefore it cannot be accessible from outside the package.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
//save by A.java
package pack1;
class A{
	void display(){
		System.out.println(&quot;Inside class A method. &quot;);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
//save by B.java
package pack2;
import pack1.*;
class B{
	public static void main(String args[]){
		A obj = new A();
		obj.display(); //compile-time error.
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;color: black;&quot;&gt;&lt;code&gt;
compile time error.
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: black; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;color: black;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;3. Protected Access Modifier:
&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The data member and method declared as &lt;b style=&quot;color: black;&quot;&gt;protected&lt;/b&gt; can be only accessible within the same package and outside the package through &lt;a href=&quot;https://www.javastudypoint.com/2018/12/inheritance-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;inheritance&lt;/span&gt;&lt;/a&gt; only. It cannot be applied to classes.&lt;br /&gt;
&lt;br /&gt;
&lt;script async=&quot;&quot; src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-7767577065803382&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;1293905187&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;color: black; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Protected Access Modifier:&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In this example, we will create two packages &lt;b&gt;&lt;i&gt;pack1&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;pack2 &lt;/i&gt;&lt;/b&gt;and class A in the package pack1 is made public so it can be accessed from outside the package but the method &lt;b&gt;&lt;i&gt;display()&lt;/i&gt;&lt;/b&gt; declared inside this package is protected, so it can be accessed from outside the class through inheritance only.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
//save by A.java
package pack1;
class A{
	protected void display(){
		System.out.println(&quot;Inside class A method. &quot;);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
//save by B.java
package pack2;
import pack1.*;
class B extens A{
	public static void main(String args[]){
		B obj = new B();
		obj.display(); 
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
inside class A method.
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;4. Public Access Modifier:&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The members, methods, and classes declared as&lt;b&gt; public&lt;/b&gt; can be accessed from anywhere. This modifier can be accessed from within the class, outside the class, within the package, and outside the package.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Public Access Modifier:&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;In this example, we will create two packages &lt;b&gt;&lt;i&gt;pack1&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;pack2&lt;/i&gt;&lt;/b&gt; and class A and method &lt;b&gt;&lt;i&gt;display()&lt;/i&gt;&lt;/b&gt; inside the package pack1 is public, so it can be accessed from anywhere.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
//save by A.java
package pack1;
public class A{
	public void display(){
		System.out.println(&quot;Inside class A method. &quot;);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
//save by B.java
package pack2;
import pack1.*;
class B{
	public static void main(String args[]){
		A obj = new A();
		obj.display(); //compile-time error.
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
inside class A method.
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;You may also like these posts:
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-final-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;1. Final keyword in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/super-keyword-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;2. 3 uses of super keyword in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-this-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;3. 6 uses of this keyword in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-oops-concepts.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;4. Java OOPs Concepts with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-control-statements.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;5. Java control statements with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/operators-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;6. Types of operators in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/02/collection-framework-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;7. Java collection framework complete tutorial.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/05/core-java-interview-questions.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;8. Top 100 java interview question and answer.&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/9084036697995820807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2019/12/access-modifiers-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/9084036697995820807'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/9084036697995820807'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2019/12/access-modifiers-in-java.html' title='Access Modifiers in Java - Private, Default, Protected, Public Modifiers'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP43T56hcrggARTob9_x5JPlhaGtJfF4FVQB3R0Ix7J67gA3nfN4xXdF199_yItyk-lfSLL5yMJhPTu4HLQMiKOngVceqBVLQ7VukWHop3HmfwN4ozox6Wj8Eim8En5iLtd0AKJH1l0zgf/s72-c/Screenshot+%2528489%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4549513797136890259.post-2210312869874777815</id><published>2019-12-25T23:12:00.000+05:30</published><updated>2019-12-25T23:12:13.367+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="packages in java"/><title type='text'>Packages in Java | How to create and use Packages in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;A &lt;b style=&quot;color: black;&quot;&gt;package in java&lt;/b&gt; is defined as the group of related classes and interfaces into a single unit. For example: Suppose you want to perform database operations, the required classes and interfaces are grouped into a single unit which is java.sql package. Therefore we can say that packages are the &lt;a href=&quot;https://www.javastudypoint.com/2018/12/encapsulation-in-java-oops.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;encapsulation&lt;/span&gt;&lt;/a&gt; mechanism to group related classes and interfaces into a single unit. There are two types of &lt;b&gt;packages in Java&lt;/b&gt;: built-in packages and user-defined packages.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Advantages of using Packages in Java:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;1. Naming Conflicts:&lt;/b&gt; There are &lt;b style=&quot;color: black;&quot;&gt;2 Date&lt;/b&gt; classes available in &lt;a href=&quot;https://www.javastudypoint.com/2018/12/encapsulation-in-java-oops.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;Java&lt;/span&gt;&lt;/a&gt;, one inside the &lt;b&gt;SQL&lt;/b&gt; package and second inside the &lt;b&gt;util&lt;/b&gt; package. So, by using the packages we can able to differentiate java.util.date and java.sql.Date. If a package statement is not there than it is impossible to have 2 date classes. By using a package, we can able to resolve &lt;b&gt;naming conflicts&lt;/b&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. Modularity and Maintainability: &lt;/b&gt;As we know, &lt;b&gt;Packages&lt;/b&gt; are the group of related classes and interfaces, therefore, Modularity and the Maintainability of the application are gone to be improved.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;3. Security:&lt;/b&gt; Suppose you have a class inside a package &lt;b&gt;pack1&lt;/b&gt;. Assume this class is not public if it is not public then outside person not able to access this class because the default is only accessible within the same &lt;b&gt;package&lt;/b&gt;. The package provides security to our component.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block; text-align:center;&quot;
     data-ad-layout=&quot;in-article&quot;
     data-ad-format=&quot;fluid&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;5403717144&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Types of packages in Java.&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;There are two types of packages in Java:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguy6A9GJx6MLWusbXyh1KYLlz686oJlUbv-E_5L1ti2YqGjuVw6zzOzuqXJLUWMBNyEaPhIjB2m9oynTd8es32WPJUu6UJn8uVuF4cPj0AuFzfdktGu8-0gNQ3EBCOD5ecMzKjYkbBJ7MP/s1600/Screenshot+%2528488%2529.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;packages in java&quot; border=&quot;0&quot; data-original-height=&quot;333&quot; data-original-width=&quot;670&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguy6A9GJx6MLWusbXyh1KYLlz686oJlUbv-E_5L1ti2YqGjuVw6zzOzuqXJLUWMBNyEaPhIjB2m9oynTd8es32WPJUu6UJn8uVuF4cPj0AuFzfdktGu8-0gNQ3EBCOD5ecMzKjYkbBJ7MP/s1600/Screenshot+%2528488%2529.png&quot; title=&quot;types of packages in java&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;1. Built-in package:&lt;/b&gt; The packages which are already defined and part of Java &lt;b&gt;API&lt;/b&gt; is known as Built-in packages. Some commonly used built-in packages are given below:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;i) java.lang:&lt;/b&gt; This package contains language support classes.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;ii) java.util:&lt;/b&gt; This package contains utility classes such as &lt;a href=&quot;https://www.javastudypoint.com/2019/02/linkedlist-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;LinkedList&lt;/span&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.javastudypoint.com/2019/03/java-dictionary-class-with-example.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;Dictionary&lt;/span&gt;&lt;/a&gt;, etc.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b style=&quot;color: black;&quot;&gt;iii) java.io:&lt;/b&gt; This package contains &lt;span style=&quot;color: black;&quot;&gt;classes&lt;/span&gt; for file read/write operations.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;iv) java.net:&lt;/b&gt; This package contains classes for networking operations.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;v) java.applet:&lt;/b&gt; This package contains classes for creating the applets.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;2. User-defined package:&lt;/b&gt; The packages that are defined by the user is known as a user-defined package.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to create packages in Java.&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Creating a package in Java is not a difficult task. You can create a package in java by using the package keyword. for example:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
package MyPackage;
&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Here &lt;b&gt;&lt;i&gt;package&lt;/i&gt;&lt;/b&gt; is a keyword and &lt;b&gt;&lt;i&gt;MyPackage&lt;/i&gt;&lt;/b&gt; is a package name.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to compile and run Java Package.&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Suppose we have a file called &lt;b&gt;&lt;i&gt;HelloWorld.java&lt;/i&gt;&lt;/b&gt;, and we want to put this file in a package world. for example:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
package World;
public class HelloWorld{
	public static void main(String args[]){
		System.out.println(&quot;Hello World&quot;);
	}
}
&lt;/code&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Now compile this file as:
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
javac -d . HelloWorld.java
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Here &lt;b&gt;-d&lt;/b&gt; specifies the destination where to put the class file and &lt;b&gt;. (dot)&lt;/b&gt; specifies the current working directory.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You can run this file as:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
java World.HelloWorld
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We need to use the fully qualified name to run the class. Here &lt;b&gt;&lt;i&gt;World&lt;/i&gt;&lt;/b&gt; is a package and &lt;b&gt;&lt;i&gt;HelloWorld&lt;/i&gt;&lt;/b&gt; is a class inside this package.
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;How to access the package from another package.&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;There are three ways to access the package from another package.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. import package.*;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. import package.classname;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;3. using a fully qualified class name.&lt;/span&gt;&lt;br/&gt;
&lt;div align=&quot;center&quot;&gt;&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- 336*280 sidebar 2 --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:inline-block;width:336px;height:280px&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;9992676996&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;1. Using a package name:&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;If we use package.* then all the&lt;a href=&quot;https://www.javastudypoint.com/2019/05/class-and-object-in-java.html&quot; target=&quot;_blank&quot;&gt; &lt;span style=&quot;color: lime;&quot;&gt;classes&lt;/span&gt; &lt;/a&gt;and interfaces of this package accessible. We can use the import keyword to access the classes and interfaces of another package to the current package. Let&#39;s see the example.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of Java package that imports the package-name.*;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
//save by class1.java.
package pack1;
public class Class1{
	public void display(){
		System.out.println(&quot;Inside class1 method.&quot;)
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
//save by Class2.java
package pack2;
import pack1.*;
class Class2{
	public static void main(String args[]){
		Class1 obj = new Class1();
		obj.display();
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
Inside class1 method.&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;2. Using the package.classname:&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;We can use the import &lt;b&gt;package.classname&lt;/b&gt; to access the only declared class of this package. Let&#39;s see the example.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;Example of the package in java using the package.classname&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
//save by class1.java.
package pack1;
public class Class1{
	public void display(){
		System.out.println(&quot;Inside class1 method.&quot;)
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
//save by Class2.java
package pack2;
import pack1.Class1;
class Class2{
	public static void main(String args[]){
		Class1 obj = new Class1();
		obj.display();
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;code&gt;
Inside class1 method.&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;font-family: verdana, sans-serif; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;3. Using a fully qualified class name.
&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;If we use a fully qualified class name then only declared class of this package will accessible and there is no need to import. In this case, we need to use a fully qualified name every time when you are accessing the class or interface.&lt;/span&gt;&lt;br/&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;
&lt;!-- techgj_sidebar(1)_AdSense1_1x1_as --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block&quot;
     data-ad-client=&quot;ca-pub-7767577065803382&quot;
     data-ad-slot=&quot;1293905187&quot;
     data-ad-format=&quot;auto&quot;
     data-full-width-responsive=&quot;true&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;br/&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;Example of a package in Java using a fully qualified class name:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
//save by class1.java.
package pack1;
public class Class1{
	public void display(){
		System.out.println(&quot;Inside class1 method.&quot;)
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
//save by Class2.java
package pack2;
class Class2{
	public static void main(String args[]){
                //using fully qualified class name.
		pack1.Class1 obj = new pack1.Class1(); 
		obj.display();
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Output:
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;language-java&quot;&gt;&lt;code&gt;
Inside class1 method.&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;You may also like these posts:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-final-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;1. Final keyword in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/super-keyword-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;2. 3 uses of super keyword in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-this-keyword.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;3. 6 uses of this keyword in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-oops-concepts.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;4. Java OOPs concepts explained with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/java-control-statements.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;5. Control statement in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/12/operators-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;6. Types of operators in java with example.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/02/collection-framework-in-java.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;7. Java collection framework complete tutorial.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.javastudypoint.com/2019/05/core-java-interview-questions.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;8. Top 100 java interview question and answer.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: verdana, sans-serif;&quot;&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://www.javastudypoint.com/feeds/2210312869874777815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.javastudypoint.com/2019/12/packages-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/2210312869874777815'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/4549513797136890259/posts/default/2210312869874777815'/><link rel='alternate' type='text/html' href='https://www.javastudypoint.com/2019/12/packages-in-java.html' title='Packages in Java | How to create and use Packages in Java'/><author><name>Prashant Srivastava</name><uri>http://www.blogger.com/profile/14922836528662474508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguy6A9GJx6MLWusbXyh1KYLlz686oJlUbv-E_5L1ti2YqGjuVw6zzOzuqXJLUWMBNyEaPhIjB2m9oynTd8es32WPJUu6UJn8uVuF4cPj0AuFzfdktGu8-0gNQ3EBCOD5ecMzKjYkbBJ7MP/s72-c/Screenshot+%2528488%2529.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>