Use the indexOf() method to search for a character from a given position.Let’s say the following is our string.String myStr = "Amit Diwan";Here, we are searching for the character “i” in the string. We are beginning the index from 4 for our search.int begnIndex = 4; System.out.println("String: "+myStr); strLastIndex = myStr.indexOf('i', begnIndex);The following is the complete example.Example Live Demopublic class Demo { public static void main(String[] args) { String myStr = "Amit Diwan"; int strLastIndex = 0; int begnIndex = 4; System.out.println("String: "+myStr); strLastIndex = myStr.indexOf('i', begnIndex); System.out.println("The index of character a in the string beginning from index "+begnIndex+" ="+strLastIndex); ... Read More
Use the indexOf() method to search for a substring from a given position.Let’s say the following is our string.String myStr = " pqrstuvwxyzpqrst";Searching for the substring “pqrs” in the string. We are beginning the index from 3 for our search.int begnIndex = 3; strLastIndex = myStr.indexOf("pqrs", begnIndex);Example Live Demopublic class Demo { public static void main(String[] args) { String myStr = "pqrstuvwxyzpqrst"; int strLastIndex = 0; int begnIndex = 3; System.out.println("String: "+myStr); strLastIndex = myStr.indexOf("pqrs", begnIndex); System.out.println("The index of substring pqrs in the string beginning from index "+begnIndex+" = "+strLastIndex); } }OutputString: pqrstuvwxyzpqrst The index of substring pqrs ... Read More
To display the position of a Substring in Java, we use the lastindexOf() method in Java. The lastindexOf() method returns the rightmost occurrence of the substring within a particular StringBuffer object.If the substring occurs more than once in the StringBuffer object, the index of the first character of the rightmost occured substring is returned. If the substring is not found, the lastIndexOf() method returns -1.Declaration − The java.lang.StringBuffer.lastIndexOf() method is declared as follows−public int lastIndexOf(String s)where s is the substring whose index needs to be foundLet us see a program which displays the position of a Substring.Example Live Demopublic class Example ... Read More
In order to change a single character in a StringBuffer object in Java, we use the setCharAt() method. The setCharAt() method sets the character at the index specified as a parameter to another character whose value is passed parameter of the setCharAt() method. The method sets a new character sequence with the only change being the character passed as the parameter at the specified index.Declaration - The java.lang.StringBuffer.setCharAt() method is declared as follows−public void setCharAt(int index, char ch)If index is greater than the length of the StringBuffer object or is negative, an IndexOutOfBoundsException is generated.Let us see a program to ... Read More
To get the arc sine of a given value in Java, we use the java.lang.Math.asin() method. The asin() method accepts a double value whose angle needs to be computed. The range of the angle returned lies in the range -pi/2 to pi/2. If the argument is NaN, then the result is NaN.When the argument is zero, then the output is a zero with the same sign as the argument.Declaration − The java.lang.Math.asin() method is declared as follows−public static double asin(double a)where a is the value whose arc sine is computed.Let us see a program to get the arc sine of ... Read More
In order to remove a character from a Java StringBuffer object, we use the deleteCharAt() method. The deleteCharAt() removes the character at the specified index. The length of resultant sequence of characters of the StringBuffer object is reduced by one.Declaration − The java.lang.StringBuffer.deleteCharAt() method is declared as follows−public StringBuffer deleteCharAt(int index)Let us see a program to illustrate the use of the deleteCharAt()Example Live Demopublic class Example { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Hello World"); sb.deleteCharAt(7); System.out.println(sb); } }OutputHello Wrld
To return all the default systems properties in Java, firstly use the System.getProperties() method.java.util.Properties prop = System.getProperties();After that, use the list() method to list all of them.prop.list(System.out);Example Live Demopublic class Demo { public static void main(String[] args) { java.util.Properties prop = System.getProperties(); System.out.println("Here are the Properties:"); prop.list(System.out); } }OutputHere are the Properties: java.runtime.name=OpenJDK Runtime Environment sun.boot.library.path=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... java.vm.version=25.141-b16 java.vm.vendor=Oracle Corporation java.vendor.url=http://java.oracle.com/ path.separator=: java.vm.name=OpenJDK 64-Bit Server VM file.encoding.pkg=sun.io user.country=US sun.java.launcher=SUN_STANDARD sun.os.patch.level=unknown java.vm.specification.name=Java Virtual Machine Specification user.dir=/home/cg/root/3757524 java.runtime.version=1.8.0_141-b16 java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment java.endorsed.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... os.arch=amd64 java.io.tmpdir=/tmp line.separator= java.vm.specification.vendor=Oracle Corporation os.name=Linux sun.jnu.encoding=UTF-8 java.library.path=/home/cg/root/GNUstep/Library/Librari... java.specification.name=Java Platform API Specification java.class.version=52.0 sun.management.compiler=HotSpot 64-Bit Tiered Compilers os.version=3.10.0-862.9.1.el7.x86_64 user.home=? user.timezone= java.awt.printerjob=sun.print.PSPrinterJob ... Read More
Use the System.getProperty() method in Java to get the Operating System name.It’s syntax is −String getProperty(String key)Above, the key is the name of the system property. Since, we want the OS name, therefore we will add the key as −os.nameExample Live Demopublic class Demo { public static void main(String[] args) { System.out.print("Operating System: "); System.out.println(System.getProperty("os.name")); } }OutputOperating System: Linux
Fair child semiconductors (founded in 1957) invented the first Integrated Circuit in 1959 that marked the microprocessor history. In 1968, Gordan Moore, Robert Noyce and Andrew Grove resigned from the Fair child semiconductors and started their own company: Integrated Electronics (Intel). In 1971, the first microprocessor Intel 4004 was invented. A microprocessor is also known as a central processing unit in which numbers of peripherals’ are fabricated on a single chip. It has ALU (arithmetic and logic unit), a control unit, registers, bus systems and a clock to perform computational tasks.Generation of Microprocessor1st GenerationThis was the period during 1971 to ... Read More
In order to remove a substring from a Java StringBuilder Object, we use the delete() method. The delete() method removes characters in a range from the sequence. The delete() method has two parameters, start, and end. Characters are removed from start to end-1 index.Declaration − The java.lang.StringBuilder.delete() method is declared as follows −public StringBuilder delete(int start, int end)Let us see an example which removes a substring from a StringBuilder.Example Live Demopublic class Example { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Welcome to Java Programming"); System.out.println("Original StringBuilder Object: " + sb.toString()); ... Read More